OPBIT - Operation Bits

no tags 

Operation bits - A new operation conducted by the secret team currently working on a project on security enhancement. Mr.Abay, the team head, has found a new pattern on the perfect squares. This can be used as a outer cover for his project as its securing power is low. So he assign you this problem to find the key based on the given conditions:

"An two adjacent perfect squares have their absolute difference as an odd number except when a and b are equal. Your task is to find the key which is defined as: 

key(a, b) where a and b are perfect squares is ( ( AND( absolute difference between every adjacent perfect squares in [a, b]) ) AND ( XOR( absolute difference between every adjacent perfect squares in [a, b]) ) )"

Find the key for the given inputs :)

Input

The input begins with a number T (1<=T<=1000) where T is the number of testcases.

T lines follow

Each line has two numbers a and b (0 < a <= b <= 10^6)

It is assured that a and b are perfect squares.

Output

For each test case print the corresponding key.

Example

Input:
2
1 4
25 49

Output:
3
0

for test case 1 we have key=(3)&(3)=3


hide comments
bubbler9903: 2016-02-18 09:27:48

Brute force gives AC even in Python :)

Dushyant Singh: 2015-06-14 10:48:33

Brute force gave AC here. But my O(1) solution gave WA! :-(

Dushyant Singh: 2015-06-02 08:27:43

@ Benkindersophobia - Please check submission ID 14374408. I am pretty sure my code is correct.

Vipul Srivastava: 2015-04-28 12:10:50

Same algo TLE in python, AC in C++

:.Mohib.:: 2015-01-09 13:05:13

Silly mistakes coast me 2 WA...Nice problem..... :)

NEXES: 2014-12-02 12:06:29

Ac in one go........

Sandeep Garhwar: 2014-07-06 15:26:47

when a==b,answer is 0 as 0&0=0

****: 2014-02-05 17:59:34

easy one....:)
AC in first go!!!!!

aqfaridi: 2014-01-25 15:53:28

weak test cases..

Vipul Pandey: 2014-01-23 17:53:03

AC in first go.

Last edit: 2014-01-25 15:44:27

Added by:Benkindersophobia
Date:2013-11-30
Time limit:0.100s
Source limit:40000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:My Own