GRIDPNTS - Grid points (speed variation)

no tags 

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.

Graphic for GridPnt

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
1 1 1
5 3 2
100 97 98 Output: 1 0
5 3
98 99

hide comments
Aditya Pande: 2012-11-25 15:44:06

will o(n) work

HWK: 2011-09-11 07:47:11

Not in all languages.

[Retired] Fendy Kosnatha: 2011-09-10 14:20:50

1s is more than enough if the code is optimal... :)

HWK: 2011-06-02 17:22:00

I've increased the number of test cases to make speed differences more obvious. The time limit was adjusted. Thus the problem is still solvable with e.g. Python or Perl.

Last edit: 2011-06-01 15:29:57

Added by:HWK
Date:2011-05-24
Time limit:1s-1.253s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64