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.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {
	static int[][] grid;

	static int res[][];

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int max = 1;
		int c = 1;
		while(max<200000) {
			max<<=1;
			c++;
		}
		int [][] occ = new int[c][200001];
		for (int i = 0; i < occ.length; i++) {
			int mask = 1<<i;
			for (int j = 1; j < occ[i].length; j++) {
				if((mask&j)==0) {
					occ[i][j]=1;
				}
			}
		}
		int[][] acc = new int[c][200001];
		for (int i = 0; i < acc.length; i++) {
			
			for (int j = 1; j < occ[i].length; j++) {
				acc[i][j] = occ[i][j]+acc[i][j-1];
			}
		}
		int t = sc.nextInt();
		while (t-- > 0) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < acc.length; i++) {
				min = Math.min(min, acc[i][r]-acc[i][l-1]);
			}
			pw.println(min);
		}
		pw.flush();
	}

	static int bs(Integer[] arr, int x) {
		int start = 0;
		int end = arr.length - 1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] > x) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		return start;
	}
}

class segTree {
	long[] arr, sTree;
	int n;

	public segTree(long[] a) {
		n = 1;
		while (n < a.length)
			n <<= 1;

		arr = new long[n + 1];
		Arrays.fill(arr, Long.MAX_VALUE);
		for (int i = 0; i < a.length; i++) {
			arr[i + 1] = a[i];
		}
		sTree = new long[n << 1];
		build(1, 1, n);
	}

	public void build(int curr, int l, int r) {
//		if(l>r)
//			return;
		if (l == r) {
			sTree[curr] = arr[curr - (n - 1)];
			return;
		}
		int mid = (l + r) >> 1;
		build(curr << 1, l, mid);
		build((curr << 1) + 1, mid + 1, r);
		sTree[curr] = Math.min(sTree[curr << 1], sTree[(curr << 1) + 1]);
	}

	public long q(int l, int r) {
		return query(1, l, r, 1, n);
	}

	public long query(int curr, int qL, int qR, int l, int r) {
		if (l >= qL && r <= qR) {
			return sTree[curr];
		}
		if (r < qL || l > qR) {
			return Long.MAX_VALUE;
		}
		int mid = (l + r) >> 1;
		long left = query((curr << 1), qL, qR, l, mid);
		long right = query((curr << 1) + 1, qL, qR, mid + 1, r);
		return Math.min(left, right);
	}

	public void update(int i, int val) {
		i = i + n - 1;
		sTree[i] = val;
		i >>= 1;
		while (i >= 1) {
			sTree[i] = sTree[i << 1] + sTree[(i << 1) + 1];
			i >>= 1;
		}
	}
}

class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

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

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

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++)
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

	public int[] nextIntArr(int n) throws IOException {
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	public long[] nextLongArr(int n) throws IOException {
		long[] arr = new long[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}
}