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.
//package com.codeforces.GlobalRound18;


import java.io.*;

public class problem022 {

    ////  How to Improve Your problem-solving skill ??
    /// ==>> Solve problems slightly above of your level ( By practise ). ***simple
    //       Otherwise You will stay as it is okk.
    /////////////////////////////////////////////////////////////////////////
    ///        How to Solve Problem in CP ?   ( if you feel problem is hard then your approach is wrong )
    // ==>> Step01 :- Understanding problem statement clearly. Then Only Move Forward
    //      Step02 :- Think a lot about Solution. if you are confident that your solution might be correct Then only Move Forward
    //      Step03 :- First think of brute force then move to optimal approach
    //      Step04 :- Finally Code ( there is no any sense to code. if you not follow about steps okk)
    ///////////////////////////////////////////////////////////////////////////
    public static void main(String[] args)throws IOException {
        Reader scan=new  Reader();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int[][] dp=new int[200001][19];
        for (int i = 1; i <=200000; i++) {
            int k=i;
            for (int j = 0; j < 19; j++) {
                if((k&1)==1){
                    dp[i][j]=dp[i-1][j]+1;
                }else {
                    dp[i][j]=dp[i-1][j];
                }
                k>>=1;
            }
        }
        int t=scan.nextInt();
        while (t-->0) {
            int l=scan.nextInt();
            int r=scan.nextInt();
            int remainnum=0;
            for (int i = 0; i < 19; i++) {
                remainnum=Math.max(remainnum,dp[r][i]-dp[l-1][i]);
            }
            int ans=(r-l+1)-remainnum;
            bw.write(ans+"");
            bw.newLine();
        }
        bw.flush();
    }
    private static long countbits(int r) {
        long count = 0;
        while (r >0) {
            count++;
            r >>= 1;
        }
        return (int)count;
    }
    //FAST READER
    static class Reader {
        public int BS = 1<<16;
        public char NC = (char)0;
        byte[] buf = new byte[BS];
        int bId = 0, size = 0;
        char c = NC;
        double num = 1;
        BufferedInputStream in;

        public Reader() {
            in = new BufferedInputStream(System.in, BS);
        }

        public Reader(String s) throws FileNotFoundException {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }

        public char nextChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public long nextLong() {
            num=1;
            boolean neg = false;
            if(c==NC)c=nextChar();
            for(;(c<'0' || c>'9'); c = nextChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=nextChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                num*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+(cur < 0 ? -1*nextLong()/num : nextLong()/num);
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=nextChar();
            while(c>32) {
                res.append(c);
                c=nextChar();
            }
            return res.toString();
        }
    }
}
