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](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the array non-zero?

A 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 (1 ≤ t ≤ 10^4) — the number of test cases. Then t cases follow.

The first line of each test case contains two integers l and r (1 ≤ l ≤ r ≤ 2 ⋅ 10^5) — the description of the array.

Output

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

Example

Input


5
1 2
2 8
4 5
1 5
100000 200000


Output


1
3
0
2
31072

Note

In the first test case, the array is [1, 2]. Currently, the bitwise AND is 0, as 1\ \& \ 2 = 0. However, after deleting 1 (or 2), the array becomes [2] (or [1]), and the bitwise AND becomes 2 (or 1). This can be proven to be the optimal, so the answer is 1.

In the second test case, the array is [2, 3, 4, 5, 6, 7, 8]. Currently, the bitwise AND is 0. However, after deleting 4, 5, and 8, the array becomes [2, 3, 6, 7], and the bitwise AND becomes 2. This can be proven to be the optimal, so the answer is 3. Note that there may be other ways to delete 3 elements.
import sys,os,io
import math 
from collections import defaultdict
def ii():
    return int(input())
def li():
    return list(map(int,input().split()))
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") 
else:
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def countSetBit(n):
    i = 0;
 
    # To store sum of set bits from 0 - N
    ans = 0;
 
    # Until n >= to 2^i
    temp = []
    while ((1 << i) <= n):
        # print(i)
        # This k will get flipped after
        # 2^i iterations
        k = True;
 
        # Change is iterator from 2^i to 1
        change = 1 << i;
        # This will loop from 0 to n for
        # every bit position
        c = 0
        for j in range(n+1):
            ans += 0 if k == True else 1;
            c += 0 if k == True else 1;
            if (change == 1):
                # When change = 1 flip the bit
                k = False if k == True else True;
                # Again set change to 2^i
                change = 1 << i;
            else:
                change -=1;
 
        # Increment the position
        i += 1;
        temp.append(c)
 
    return temp[::-1];

def solve():
    l,r = li()
    a = countSetBit(r)
    # print(a)
    b = countSetBit(l-1)
    # print(b)
    x = max(len(a),len(b))
    a = [0]*(x-len(a))+a
    b = [0]*(x-len(b))+b
    ans =0
    for i in range(x):
        a[i] = abs(a[i]-b[i])
        ans = max(ans , abs(a[i]-b[i]))
    # print("a",a)
    print(r-l+1-ans)


t = 1
t = ii()
for _ in range(t):
    solve()
