And It's Non-Zero

 You are given an array consisting of all integers from 

[l,r] inclusive. For example, if l=2 and r=5, the array would be [2,3,4,5]. What's the minimum number of elements you can delete to make the bitwise AND of the array non-zero?

bitwise AND is a binary operation that takes two equal-length binary representations and performs the AND operation on each pair of the corresponding bits.

Input

The first line contains one integer t (1t104) — the number of test cases. Then t cases follow.

The first line of each test case contains two integers l and r (1lr2105) — the description of the array.

Output

For each test case, output a single integer — the answer to the problem.

Example
input
Copy
5
1 2
2 8
4 5
1 5
100000 200000
output
Copy
1
3
0
2
31072
Previous
Next Post »