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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class itsNonZero {

	//number of digits in a number done quickly
		//int n = Math.floor(Math.log10(N)) + 1;
		
		//rotate elements in an arraylist
		//Collections.rotate(a);
		// copy an array or a part of an array
		//Arrays.copy();
		//Arrays.copyOfRange();
		
		//Collections.
		//2d arraylist adj list
	//ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>();
	//for (int i = 0; i < n; i++)adj.add(new ArrayList<Integer>());
	/*
	 -Binary search
	 int lo = 0;
	 int hi = highest val possible;
	 while (lo <= hi){
	 int mid = (lo+hi)/2;
	 
	 if (check){
	 
	 	}else {
	 	
	 	}
	 }
	 */
		
		
		
	//Custom Comparators
	/*
	 //ArrayList<comp> a = new ArrayList<comp>();
	 //long [] a = new new long [n];
	 
	 class comp implements Comparable<comp> {

		public int a, b;

		public comp(int a, int b) {
			this.a = a;
			this.b = b;
		}

		public int compareTo(comp other) {
		//sort by 1 criteria
		 //return Integer.compare(this.a. other.a);
		  
		  //sort by 2 criteria
			//if (this.a != other.a) {
			//	return Integer.compare(this.a, other.a);
			//} else {
				return Integer.compare(other.b, this.b);
			//}
		}
	}
	 */
		
		
		
	//MultiSet
	/*
	 static void add(int x){
		if(multiset.containsKey(x)){
			multiset.put(x, multiset.get(x) + 1);
		} else {
			multiset.put(x, 1);
		}
	}

	static void remove(int x){
		multiset.put(x, multiset.get(x) - 1);
		if(multiset.get(x) == 0){
			multiset.remove(x);
		}
	}
	 */
	 
		
	//DFS and other related items
	//ArrayList<ArrayList<Integer>> adj = new ArrayList<ArrayList<Integer>>();
	//for (int i = 0; i < n; i++)adj.add(new ArrayList<Integer>());
	//boolean [] visited = new boolean [n];
	/*
	 static void dfs(int node) {
			if (visited[node]) return;
			
			nodes++;
			visited[node] = true;
			for (int neighbor : adj.get(node)) {
				dfs(neighbor);
			}
	 */
	 

		
	//Floodfill
	/*
	 static void floodfill(int r, int c, char curC) {
		if (r < x || r >= 0 || c < y || c >= 0) {
			return;
		} 
		if(visited[r][c] || grid[r][c] != curC) {
			return;
		}
		visited[r][c] = true;
		size++;
		
		floodfill(r+1, c, curC);
		floodfill(r-1, c, curC);
		floodfill(r, c+1, curC);
		floodfill(r, c-1, curC);
	}
	 */
		
		
	//2 pointers
	/*
	 int l = 0, r = 0, cur = 0, ans = 0;
			while (l < n && r < n) {
				while (r < n) {
					r++;
					if ((check condition)) {
						r--;
						break;
					}
				}

				l++;
			}
	 */
		
		
	//mod int template
		/*static int mod(int a, int m)
	{
	    return (a%m + m) % m;
	}*/
		
		
		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;
	        }
	    }
		
		
		
		public static void main(String[] args) throws IOException {
			PrintWriter out = new PrintWriter(System.out);
			FastReader in = new FastReader();
			 int t = in.nextInt();
			 int [][] a = new int [200001][18];
			 for (int i = 1; i < 200001; i++) {
				 for (int j = 0; j < 18; j++) {
					a[i][j] += a[i-1][j];
					if (((i>>j) & 1) == 1)
						a[i][j]++;
				 }
			 }
			 for (int ie = 0; ie < t; ie++) {
			 int l = in.nextInt();
			 int r = in.nextInt();
			 int max = a[r][0] - a[l-1][0];
			 
			 for (int i = 1; i < 18; i++) {
				 max = Math.max(max, a[r][i]-a[l-1][i]);
			 }
			 
			out.println((1+r-l)-max);
			 }
			 out.close();

	}

}
