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 javax.swing.plaf.IconUIResource;
import java.lang.reflect.Array;
import java.text.CollationElementIterator;
import java.util.*;
import java.io.*;

//Timus judge id- 323935JJ


public class Main {




    //----------------------------------------------------------------------------------------------
    public static class Pair implements Comparable<Pair> {
        int x=0,y=0;
        int z=0;
        public Pair(int a, int b) {
            this.x=a;
            this.y=b;

        }

        public int compareTo(Pair o) {
            return this.x - o.x;
        }
    }


    public static int mod = (int) (1e9 + 7);
    static int ans = Integer.MAX_VALUE;

    public static void main(String hi[]) throws Exception {
        FastReader sc = new FastReader();
        int t =sc.nextInt();
        while(t-->0)
        {
           int l =sc.nextInt(),r=sc.nextInt();
           int[] a= new int[32];
           int[] b = new int[32];

           int x=l,ind =0;
           while(x>0)
           {
               int temp=x&1;
               if(temp==1)
                   a[ind]++;
               ind++;
               x/=2;
           }

           x=r;
           ind=0;

            while(x>0)
            {
                int temp=x&1;
                if(temp==1)
                    b[ind]++;
                ind++;
                x/=2;
            }

            int k=2;
            int max=Integer.MIN_VALUE;

            for(int i=0;i<20;i++)
            {
               int p=0,q=0;
                if((r+1)%k==0)
                    p=((r+1)/k)*(k/2);
                else {
                    if(b[i]==1)
                        p=(((r+1)/k)*(k/2)+Math.max((r+1)%k-k/2,0));
                    else {

                        p=((r+1)/k)*(k/2);
                    }
                }


                if((l+1)%k==0)
                    q=((l+1)/k)*(k/2);
                else {
                    if(a[i]==1)
                        q=(((l+1)/k)*(k/2)+Math.max((l+1)%k-k/2,0));
                    else {

                        q=((l+1)/k)*(k/2);
                    }
                }

//                System.out.println(p+" "+q);

                if(a[i]==1)
                    max=Math.max(p-q+1,max);
                else max=Math.max(p-q,max);

                k*=2;
            }

            System.out.println(r-l+1-max);

        }

    }

    static int find(int[] a,int x)
    {
        if(a[x]==-1)
            return x;
        else return find(a,a[x]);
    }





    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }


    static long gcdl(long a, long b)
    {
        if (a == 0)
            return b;
        return gcdl(b % a, a);
    }

    // method to return LCM of two numbers
    static long lcml(long a, long b)
    {
        return (a / gcdl(a, b)) * b;
    }


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;

        }
    }
}

