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.
from collections import defaultdict


def mid(a, b):
    return (b - a + 1) // 2


def met1(a, b, p):
    if a > b:
        return 0
    if a // 2 ** p == b // 2 ** p:
        return b - a + 1 if b % 2 ** (p + 1) >= 2 ** p else 0
    else:
        if b % 2 ** (p + 1) >= 2 ** p:
            return b - (next_smaller(b, p + 1) + 2 ** p) + 1
        else:
            return next_larger(a, p + 1) - a


def met2(a, b, p):
    return met1(a, next_larger(a, p + 1) - 1, p) + mid(next_larger(a, p + 1),
                                                       next_smaller(b, p + 1) - 1) + met1(
        next_smaller(b, p + 1), b, p)


def next_smaller(a, p):
    return (a // 2 ** p) * 2 ** p


def next_larger(a, p):
    return (a // 2 ** p + 1) * 2 ** p


def bit_sets(a, b, p):
    if a % 2 ** (p + 1) == 0 and b % 2 ** (p + 1) == 2 ** (p + 1) - 1:
        return mid(a, b)
    if a // 2 ** (p + 1) == b // 2 ** (p + 1):
        return met1(a, b, p)
    else:
        return met2(a, b, p)


d = defaultdict(int)
for _ in range(int(input())):
    l, r = map(int, input().split())
    if (l, r) in d:
        print(d[(l, r)])
        continue
    res, ln, mx = float('inf'), r - l + 1, len(bin(r))
    for set_bit in range(mx - 1):
        cur = bit_sets(l, r, set_bit)
        res = min(res, ln - cur)
    print(res)
    d[(l, r)] = res
