spoj#GRIDPNTS. Grid points (speed variation)
Grid points (speed variation)
There's a Cartesian lattice with 0<=x,y<=n. Given one point (x1, y1>0) in this lattice rotating clockwise as little as possible around the origin find the next point (x2, y2). The given and searched points mustn't have another point between the origin (0, 0) and this point itself.
x1, y1, x2, y2 are non-negative integers.
Input
In the first line the number T (T<10000) of test cases.
Then T lines with the space-separated n (1<=n<=1000000), x1 and y1.
Output
For each test case the space-separated x2 and y2.
Example
Input: 3</p>
1 1 1
5 3 2
100 97 98Output: 1 0
5 3
98 99