Life Goes On!

abcdef123 MBSTU CSE Junior IDPC 2k2...
Limits 1s, 128 MB

Skinny Pete lives far away from locality on his own. Two days ago he met Badger in a forest who was looking for knowledges to solve a problem. Skinny Pete and Badger bonded immediately, as Pete never had any friends, it was refreshing for him to have human companion. So, Skinny Pete decides to help Badger by solving his problem.

Badger has a machine which produces an array size of RL+1R-L+1 containing all integers from LL to RR exactly once i.e. L,L+1,L+2,.,R2,R1,RL,L+1,L+2,….,R-2,R-1,R. He will have to find a minimum integer X(0XL)X(0 \leq X \leq L) which will be subtracted from every integers of array exactly once. After that, resulting array’s total XORXOR value must be 00. By using his divine knowledge, Skinny Pete gives him the answer or tell him there’s no such XX. After hearing the solution, Badger returns to his family and Skinny Pere becomes lonely again.

Now, you have the machine Badger used to have. You have to find the answer to the problem or tell them there isn’t one. Note that you have to minimize the value of XX.


The first line will contain an integer T(1T105)T(1 \leq T \leq 10^5).

Each line will contain two integers L,R(0LR1018)L, R (0 \leq L \leq R \leq 10^{18}).


For each test case, print a single line containing an integer X(0XL)X(0 \leq X \leq L) and it will have to be as minimum as possible. If there is no answer, print 1-1.


4 7
7 10
11 44355

In first test case, the array is [4,5,6,7][4,5,6,7]. XORXOR of the array is 00. So we don’t have to subtract anything.

In second test case, XORXOR of the array is 1212. If we subtract 11 from every element of the array, XORXOR of the array will become 00.


Login to submit.


62% Solution Ratio
setulovelegendEarliest, 3M ago
fahimcp495Fastest, 0.0s
user.435401Lightest, 5.7 MB
fahimcp495Shortest, 666B
Toph uses cookies. By continuing you agree to our Cookie Policy.