#P9815. wbyblD
wbyblD
Background
Problem D. I do not want to be hacked!!!
Problem Description
There are points in a line, numbered . For point , there are two integers , where . Initially, define .
Suppose you are currently at point , and the current moving direction is . Initially, .
You will move in the following way until after some change of you get or .
- If , first increase by . Then if , set to ; otherwise, keep unchanged. Finally, decrease by .
- If , first decrease by . Then if , set to ; otherwise, keep unchanged. Finally, decrease by .
Ask which point number will be at when the process ends. In fact, in the end, can only be at point or point .
Input Format
This problem has multiple sets of testdata. The first line contains a positive integer , the number of test cases, followed by test cases.
For each test case, the first line contains a positive integer .
Then follow lines, each containing two non-negative integers , representing the initial values of .
Output Format
For each test case, output one line with one integer, indicating which point number will be at when the process ends.
3
1
1 1
3
0 1
1 1
1 0
3
0 1
2 3
4 5
0
4
0
Hint
Sample Explanation
For the st sample test case, changes as .
For the nd sample test case, changes as $(0,1)\to (1,1)\to (2,1)\to (2,-1)\to (1,-1)\to (1,1)\to (2,1)\to (3,1)\to (3,-1)\to (2,-1)\to (2,1)\to (3,1)\to (4,1)$.
For the rd sample test case, changes as $(0,1)\to (1,1)\to (2,1)\to (2,-1)\to (1,-1)\to (1,1)\to (2,1)\to (2,-1)\to (1,-1)\to (0,-1)$.
Constraints and Notes
For the first of the test points, it is guaranteed that .
For the first of the test points, it is guaranteed that .
For the other of the test points, it is guaranteed that , , and are generated uniformly at random within the specified range. In particular, it is guaranteed that for all test points except this part, .
For all test points, it is guaranteed that , , , .
Translated by ChatGPT 5