Micro and Sweet Distribution
Practice
3.8 (28 votes)
Ad Hoc
Approved
Data structures
Easy
Problem
43% Success 6933 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
20 votes
Tags:
ApprovedEasy
Points:30
21 votes
Tags:
ArraysData StructuresMulti-dimensional
Points:30
49 votes
Tags:
ArraysData StructuresEasyMulti-dimensional