All Tracks Data Structures Arrays Multi-dimensional Problem

Micro and Sweet Distribution
Tag(s):

Ad-Hoc, Data Structures, Easy-Medium

Problem
Editorial
Analytics

It's sweet distribution day in Micro's school. He's very happy. All the students in Micro's class are sitting on chairs which are arranged in a matrix of size $$N \times M$$ i.e. there are $$N$$ rows of chairs numbered from $$1$$ to $$N$$ and in each row there are $$M$$ chairs numbered from $$1$$ to $$M$$. Micro is sitting at coordinate $$(D_x, D_y)$$ ($$D_y^{th}$$ chair of $$D_x^{th}$$ row). Teacher gives the box to a student sitting in one of the four corners: $$(1,1)$$, $$(1, M)$$, $$(N, 1)$$ or $$(N,M)$$. Students have to take one sweet from the box and pass the box to the next student (student sitting to left, right, front or back). For a student sitting at coordinate $$(x, y)$$, he'll follow the following priority order:

  1. If there is a student in the Right who has not received sweet, then pass it right $$(x, y+1)$$.
  2. If there is a student in the Left who has not received sweet, then pass it left $$(x, y-1)$$.
  3. If there is a student in the Front who has not received sweet, then pass it front $$(x-1, y)$$.
  4. If there is a student in the Back who has not received sweet, then pass it back $$(x+1, y)$$.
  5. Shout Over, meaning that all students have received sweets.

Now, Micro is curious to find out the direction in which he'll have to pass the sweet box. Since there are a lot of students in Micro's class, it will take long for the box to reach him, and you know Micro, he just can't wait. So he asks you to find out the direction in which he'll have to pass the box, or will he have to shout Over.

Input:
First line consists of a single integer, $$T$$, denoting the number of test cases. Each test case consists of three lines.
First line of each test consists of two space separated integer denoting $$N$$ and $$M$$.
Second line of each test case consists of two space separated integers $$S_x$$ and $$S_y$$, denoting the coordinate of the corner from which sweet distribution starts.
Third line of each test case consists of two space separated integers denoting $$D_x$$ and $$D_y$$, coordinates of Micro.

Output:
For each test case, print "Left", "Right", "Front", "Back", "Over", depending on whether Micro will pass the box to student in left, right, front or back, or if he'll shout over.

Constraints:
$$1 \le T \le 10^5$$
$$1 \le N, M \le 10^3$$
$$1 \le D_x \le N$$
$$1 \le D_y \le M$$
$$S_x = 1$$ or $$S_x = N$$
$$S_y = 1 $$ or $$ S_y = M$$

SAMPLE INPUT
2
3 3
1 1
3 3
2 3
1 3
2 2
SAMPLE OUTPUT
Over
Right
Explanation

In first test case Micro is the last student to receive sweet box, so he'll shout Over.
In second test case Micro is sitting in middle chair of second row, and there is a student in his right i.e. at $$(2, 3)$$ who has not received sweet, so he'll pass it right.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

March Easy '17

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications