Problem:
You are given two distinct non-negative integers x and y. Consider two infinite sequences a1,a2,a3,… and b1,b2,b3,…, where
- an=n⊕x;
- bn=n⊕y.
Here, x⊕y denotes the bitwise XOR operation of integers x and y.
For example, with x=6, the first 8 elements of sequence a will look as follows: [7,4,5,2,3,0,1,14,…]. Note that the indices of elements start with 1.
Your task is to find the length of the longest common subsegment† of sequences a and b. In other words, find the maximum integer m such that ai=bj,ai+1=bj+1,…,ai+m−1=bj+m−1 for some i,j≥1.
†A subsegment of sequence p is a sequence pl,pl+1,…,pr, where 1≤l≤r.
Input Format:
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The only line of each test case contains two integers x and y (0≤x,y≤109,x=y) — the parameters of the sequences.
Output Format:
For each test case, output a single integer — the length of the longest common subsegment.
Note:
In the first test case, the first 7 elements of sequences a and b are as follows:
a=[1,2,3,4,5,6,7,…]
b=[0,3,2,5,4,7,6,…]
It can be shown that there isn't a positive integer k such that the sequence [k,k+1] occurs in b as a subsegment. So the answer is 1.
In the third test case, the first 20 elements of sequences a and b are as follows:
a=[56,59,58,61,60,63,62,49,48,51,50,53,52,55,54,41, 40, 43, 42,45,…]
b=[36,39,38,33,32,35,34,45,44,47,46,41, 40, 43, 42,53,52,55,54,49,…]
It can be shown that one of the longest common subsegments is the subsegment [41,40,43,42] with a length of 4.