description: 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.
solution: 
  
  
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Scanner;
  import java.util.StringTokenizer;
  
  
  
  public class CodeForces {
  
      
      static class FastScanner {
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st=new StringTokenizer("");
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st=new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
                  
                  long[] readLongArray(int n) {
  			long[] a =new long[n];
  			for (int i=0; i<n; i++) a[i]=nextLong();
  			return a;
  		}
                  
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
       
   
  	
      
      
      public static int gcd(int a, int b)
      {
          if (a == 0)
              return b;
            
          return gcd(b%a, a);
      }
      
      
      public static long gcd(long a, long b)
      {
          if (a == 0)
              return b;
            
          return gcd(b%a, a);
      }
      
      
      
      static void sort (int[]a){
          ArrayList<Integer> b = new ArrayList<>();
          for(int i:a)b.add(i);
          Collections.sort(b);
          for(int i=0;i<b.size();i++){
              a[i]=b.get(i);
          }
      }
      
      
      static void sort (long[]a){
          ArrayList<Long> b = new ArrayList<>();
          for(long i:a)b.add(i);
          Collections.sort(b);
          for(int i=0;i<b.size();i++){
              a[i]=b.get(i);
          }
      }
      
      
      static ArrayList<Integer> sieveOfEratosthenes(int n)
      {
          boolean prime[] = new boolean[n + 1];
          for (int i = 0; i <= n; i++)
              prime[i] = true;
   
          for (int p = 2; p * p <= n; p++)
          {
            
              if (prime[p] == true)
              {
                  for (int i = p * p; i <= n; i += p)
                      prime[i] = false;
              }
          }
   
          
          ArrayList<Integer> ans = new ArrayList<>();
          for (int i = 2; i <= n; i++)
          {
              if (prime[i] == true)
                  ans.add(i);
          }
          
          return ans;
      }
   
      
      
  
      
     
      static int binarySearchSmallerOrEqual(int arr[], int n, int key)
    {
      int left = 0, right = n;
   
      int mid = 0;
      while (left < right) {
        mid = (right + left) >> 1;
   
        if (arr[mid] == key) {
   
         
          while (mid + 1 < n && arr[mid + 1] == key)
            mid++;
          break;
        }
   
        else if (arr[mid] > key)
          right = mid;
   
        else
          left = mid + 1;
      }
   
      while (mid > -1 && arr[mid] > key)
        mid--;
   
      return mid;
    }
   
      
      static int binarySearch(int arr[], int x)
      {
          int l = 0, r = arr.length - 1;
          while (l <= r) {
              int m = l + (r - l) / 2;
               if (arr[m] == x)
                  return m;
              if (arr[m] < x)
                  l = m + 1;
              else
                  r = m - 1;
          }
          return -1;
      }
      
      
      static int binarySearch(long arr[], long x)
      {
          int l = 0, r = arr.length - 1;
          while (l <= r) {
              int m = l + (r - l) / 2;
               if (arr[m] == x)
                  return m;
              if (arr[m] < x)
                  l = m + 1;
              else
                  r = m - 1;
          }
          return -1;
      }
      static void init(int[]arr,int val){
          for(int i=0;i<arr.length;i++){
              arr[i]=val;
          }
      }
      
      static void init(long[]arr,long val){
          for(int i=0;i<arr.length;i++){
              arr[i]=val;
          }
      }
      
      
      
      
      
      
      static String ConvertBinary(int[] binary, int id)
      {
          String a ="0";
          for (int i = id - 1; i >= 0; i--)
              a+=binary[i];
          
          
          return a;
      }
   
      public static String decimalToBinary(int num)
      {
          int[] binary = new int[35];
          int id = 0;
   
          while (num > 0) {
              binary[id++] = num % 2;
              num = num / 2;
          }
           return ConvertBinary(binary, id);
      }
  
      
      
      
      
  
      public static void main(String[] args)  {
      
          FastScanner fs = new FastScanner();
          Scanner str = new Scanner(System.in);
          StringBuilder sb = new StringBuilder();
          
          
         
          int t = fs.nextInt();
          
          for (int q=0;q<t;q++){
              int n = fs.nextInt();
              int m = fs.nextInt();
            
              
              String bin = decimalToBinary(m);
              
              while(bin.charAt(0)=='0'&&bin.length()>1){
                  bin=bin.replaceFirst("0", "");
              }
              
              
              
              int min = 20000001;
              m++;
              for (int i=0;i<bin.length();i++){
                  int nums =(int) Math.pow(2,i);
                  
                  
                  int zerosM =(m/nums)%2==0?(m/nums/2)*nums+m%nums:(m/nums/2+1)*nums;
                  
                  int zerosN =(n/nums)%2==0?(n/nums/2)*nums+n%nums:(n/nums/2+1)*nums;
                  min=Math.min(min,zerosM-zerosN);
              }
             
              
              sb.append(min).append("\n");
          }
          
          System.out.println(sb.toString());
  }
      
      
     
  }
  
  