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.io.PrintWriter;
  import java.text.DecimalFormat;
  import java.util.*;
  
  //import sun.nio.fs.RegistryFileTypeDetector;
  
  
   
  public class Codeforces {
  	static int mod= 1000000007;
  	
  	public static void main(String[] args) throws Exception {
  		PrintWriter out=new PrintWriter(System.out);
  		FastScanner fs=new FastScanner();
  		int t=fs.nextInt();
  		
  		outer:while(t-->0) {
  			int l=fs.nextInt(), r=fs.nextInt();
  			int ans=Integer.MAX_VALUE;
  			for(int i=1;i<=30;i++) {
  				int cur=find(l,r,i);
  				ans=Math.min(ans, cur);
  //				out.println(cur);
  			}
  //			System.out.println(solve(8,f));
  			out.println(ans);
  		}
  		
  		out.close();
  		
  	}
  	static int find(int l,int r,int p) {
  		return solve(r,p)-solve(l-1,p);
  	}
  	static int solve(int n,int p) {
  		n++;
  		int div= 1<<p;
  		int ans=(n/div)*(1<<(p-1));
  		ans+= Math.min(n%div,div/2);
  		return ans;
  	}
  	static long pow(long a,long b) {
  		if(b<0) return 1;
  		long res=1;
  		while(b!=0) {
  			if((b&1)!=0) {
  				res*=a;
  				res%=mod;
  			}
  			a*=a;
  			a%=mod;
  			b=b>>1;
  		}
  		return res;
  	}
  	static int gcd(int  a,int  b) {
  		if(b==0) return a;
  		return gcd(b,a%b);
  	}
  	static long nck(int n,int k) {
  		if(k>n) return 0;
  		long res=1;
  		res*=fact(n);
  		res%=mod;
  		res*=modInv(fact(k));
  		res%=mod;
  		res*=modInv(fact(n-k)); 
  		res%=mod;
  		return res;
  	}
  	static long fact(long n) {
  //		return fact[(int)n];
  		long res=1;
  		for(int i=2;i<=n;i++) {
  			res*=i;
  			res%=mod;
  		}
  		return res;
  	}
  	
  	static long modInv(long n) {
  		return pow(n,mod-2);
  	}
  	
  	static void sort(int[] a) {
  		//suffle
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			int oi=r.nextInt(n);
  			int temp=a[i];
  			a[i]=a[oi];
  			a[oi]=temp;
  		}
  		
  		//then sort
  		Arrays.sort(a);
  	}
  	
  	// Use this to input code since it is faster than a Scanner
  	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());
  		}
  		long[] lreadArray(int n) {
  			long a[]=new long[n];
  			for(int i=0;i<n;i++) a[i]=nextLong();
  			return a;
  		}
  		int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
   
  }