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 collections
# import random
# import math
# import itertools
# import math
# import math
#import bisect
# from collections import defaultdict
# import itertools
# from sys import stdin, stdout
# import math
# import math
# import bisect
# import bisect
# import collections
# import itertools
# import math
# import collections
# import itertools
# import math
import bisect
import collections
import math
import sys

# import operator
# from decimal import Decimal

# sys.setrecursionlimit(10**6)





p2D = lambda x: print(*x, sep="\n")


def II(): return int(sys.stdin.buffer.readline())


def MI(): return map(int, sys.stdin.buffer.readline().split())


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def BI(): return sys.stdin.buffer.readline().rstrip()


def SI(): return sys.stdin.buffer.readline().rstrip().decode()


def li(): return [int(i) for i in input().split()]


def lli(rows): return [li() for _ in range(rows)]


def si(): return input()


def ii(): return int(input())


def ins(): return input().split()


# mod = 10**9+7
# fval = [1]
# for i in range(1,200001):
#     x = (fval[-1]*i)%mod
#     fval.append(x)
#
# ifac = [1]*(200001)
# ifac[200000] = pow(fval[200000], -1, mod)
# for i in range(200000-1, 1, -1): ifac[i] = ifac[i+1]*(i+1)%mod
# _________________ For taking Input from the Text Files __________________
# import os.path
#
# if (os.path.exists('input.txt')):
#     sys.stdin = open("input.txt", "r")
#     sys.stdout = open("output.txt", "w")
#     sys.stderr = open("error.txt", "w")

def drank(d, processing, da, rank):
    tmp = 10 ** 9
    if len(d[da]) == 1:
        return 1
    for di in d[da]:
        if processing[di - 1] == 0:
            processing[di - 1] = 1
            tmp = min(tmp, drank(d, processing, di, rank))
            processing[di - 1] = 0
    rank[da - 1] = tmp + 1
    return tmp + 1



def binary_search(n, a):
    l = len(a)
    low = 0
    high = l-1
    while high>=low:
        mid = (high+low)//2
        if a[mid] == n:
            return mid
        elif a[mid]>n:
            high = mid-1
        else:
            low = mid+1
    return -1

is_prime = [True]*(10**6+1)
def primeseive(n):
    is_prime[0] = is_prime[1] = False
    i = 2
    while i*i<=n:
        if is_prime[i] == True:
            for j in range(i*i,n+1,i):
                is_prime[j] = False
        i+=1
#
# m ,n = li()
#     p = [li() for i in range(m)]
#     print(p)
#     a = []
#     if m<n:
#         for i in range(n):
#             z = [p[j][i] for j in range(m)]
#             a.append(max(z))
#         return min(a)
#     else:
#         x = 0

def solve():
    l , r = li()
    if l == r:
        return 0
    p = 1
    ans = 0
    while True:
        x = 2**p
        max_ones = ((r+1)//x)*(x//2)+ max((r+1)%x-x//2, 0)
        min_ones = ((l)//x)*(x//2)+ max((l)%x-x//2, 0)
        #print(max_ones)
        #print(min_ones)
        ans = max(ans, max_ones - min_ones)
        if x>r:
            break
        p+=1
    return (r-l+1)-ans



def main():
    #primeseive(10**6)
    #print(is_prime)

    for _ in range(ii()):
        #si()
        #print(solve(), flush=True)
        sys.stdout.write(str(solve()) + "\n")
    #print(solve())

    #     z += str(ans) + '\n'
    # print(len(ans), ' '.join(map(str, ans)), sep='\n')
    # stdout.write(z)


# for interactive problems
# print("? {} {}".format(l,m), flush=True)
# or print this after each print statement
# sys.stdout.flush()


if __name__ == "__main__":
    main()