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 java.io.*;
import java.util.*;

public class B {
    public static void main(String[] args) {
        Pre.init();
        for (int t = IO.getInt(), i = 0; i < t; i++)
            new SolB().solve();
        IO.close();
    }
}

class SolB {

    int l, r;

    SolB() {
        l = IO.getInt();
        r = IO.getInt();
    }

    void solve() {
        int ans = r-l+1;
        for (int i = 0; i < Constants.MAX_BIT; i++) {
            int ones = Pre.bitCount[r][i][1] - Pre.bitCount[l-1][i][1];
            ans = Integer.min(ans, r-l+1-ones);
        }
        IO.writer.println(ans);
    }
}

class Pre {

    //common pre-computation for all test cases

    static int[][][] bitCount;

    static void init() {
        bitCount = new int[Constants.MAX_R][Constants.MAX_BIT][2];

        for (int i = 0; i < Constants.MAX_BIT; i++)
            bitCount[0][i][0] = 1;

        for (int i = 1; i < Constants.MAX_R; i++) {
            boolean[] mask = bitMask(i);
            for (int j = 0; j < Constants.MAX_BIT; j++) {
                bitCount[i][j][0] = bitCount[i-1][j][0];
                bitCount[i][j][1] = bitCount[i-1][j][1];
                if (mask[j])
                    bitCount[i][j][1]++;
                else
                    bitCount[i][j][0]++;
            }   
        }
    }

    static boolean[] bitMask(int v) {
        boolean[] mask = new boolean[Constants.MAX_BIT];
        int p = 0;
        while (v > 0) {
            mask[p++] = v % 2 == 0 ? false : true;
            v /= 2;
        }
        return mask;
    }
}

class Constants {
    static int MOD = 1000000007;
    static int MAX_R = 200005;
    static int MAX_BIT = 20;
}

class IO {
    public static final PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    private static byte[] bytes = new byte[1<<15];
    private static int i, n;

    private static StringTokenizer tokens;

    private static void scan() {
        if (i == n) {
            i = 0;
            try {
                n = System.in.read(bytes);
            } catch (IOException e) {}
        }
    }

    private static byte getByte() {
        scan();
        return i < n ? bytes[i++] : 0;
    }

    private static byte skip() {
        byte b = getByte();
        while (b <= ' ')
            b = getByte();
        return b;
    }

    public static int getInt() {
        int a = 0;
        for (byte b = skip(); b > ' '; b = getByte())
            a = a * 10 + (b - '0');
        return a;
    }

    public static long getLong() {
        long a = 0l;
        for (byte b = skip(); b > ' '; b = getByte())
            a = a * 10 + (b - '0');
        return a;
    }

    public static String readLine() {
        StringBuilder sb = new StringBuilder();
        for (byte b = getByte(); b >= ' '; b = getByte())
            sb.append((char) b);
        return sb.toString();
    }

    private static void initTokens() {
        while (null == tokens || !tokens.hasMoreTokens())
            tokens = new StringTokenizer(readLine());
    }

    public static String next() {
        initTokens();
        return tokens.nextToken();
    }

    public static String next(String delim) {
        initTokens();
        return tokens.nextToken(delim);
    }

    public static int nextInt() {
        return Integer.parseInt(next());
    }

    public static long nextLong() {
        return Long.parseLong(next());
    }

    public static void close() {
        writer.close();
    }
}