Giga-xor

Time limit: 2s Memory limit: 256MB Input: Output:

An interval [a,b][a, b] is a giga-xor interval if and only if the xor sum of the natural numbers inside the interval [a,b][a, b] is equal to 00, where aa and bb are natural numbers.

Strictly speaking, an interval [a,b][a, b] is giga-xor if and only if a(a+1)(a+2)...b=0a ⊕ (a + 1) ⊕ (a + 2) ⊕ ... ⊕ b = 0.

You are given TT pairs of numbers (a,b)(a, b). For each pair, you need to find the length of the shortest interval [x,y][x, y] such that 1xaby1 \le x \le a \le b \le y and [x,y][x, y] is a giga-xor interval.

Input

The first line contains TT (1T51051 ≤ T ≤ 5 \cdot 10^5), the number of pairs.

On the following TT lines, there are 22 integers aa, bb (1ab10181 ≤ a ≤ b ≤ 10^{18}).

For tests worth 1010 points, b100b ≤ 100

For tests worth 3030 more points, b106b ≤ 10^6

Output

Print on TT lines, the answer for each pair.

Example

stdin

5	
4 5
2 3
1 7
8 8
1 10

stdout

4
3
7
4
11

Log in or sign up to be able to send submissions!