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.*;
  import java.util.*;
  
  public class NonZero {
      public static void main(String[] args) throws IOException {
          FastIO fr = new FastIO();
          PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
  		int t = fr.nextInt();
  
  		// precompute bits of numbers from 1 to 200000
  		int[][] dp = new int[18][200001];
  
  		for (int i = 0; i < 18; i++) {
  			int val = 1 << i; 
  			for (int j = 1; j <= 200000; j++) {
  				if ((j & val) != 0) dp[i][j] = 1;
  				dp[i][j] += dp[i][j - 1];
  			}
  		}
  
  		while (t-- > 0) {
  			int l = fr.nextInt();
  			int r = fr.nextInt();
  
  			int n = r - l + 1;
  
  			long ans = Integer.MAX_VALUE;
  
  			for (int i = 0; i < 18; i++) {
  				int count = dp[i][r] - dp[i][l-1];
  				
  				ans = Math.min(ans, n - count);
  			}
  
  			pr.println(ans);
  		}
  
  		pr.close();
      }
  
      static class Pair {
          int x, y;
  
          public Pair(int x, int y) {
              this.x = x;
              this.y = y;
          }
      }
  
      static int gcd(int a, int b) {
          if (b == 0) return a;
          return gcd(b, a % b);
      }
  
      static int toInt(String s) {
          return Integer.parseInt(s);
      }
  
      // MERGE SORT IMPLEMENTATION
      void sort(int[] arr, int l, int r) {
          if (l < r) {
              int m = l + (r - l) / 2;
  
              sort(arr, l, m);
              sort(arr, m + 1, r);
  
              // call merge
              merge(arr, l, m, r);
          }
      }
  
      void merge(int[] arr, int l, int m, int r) {
          // find sizes
          int len1 = m - l + 1;
          int len2 = r - m;
  
          int[] L = new int[len1];
          int[] R = new int[len2];
  
          // push to copies
          for (int i = 0; i < L.length; i++)
              L[i] = arr[l + i];
          for (int i = 0; i < R.length; i++) {
              R[i] = arr[m + 1 + i];
          }
  
          // fill in new array
          int i = 0, j = 0;
          int k = l;
          while (i < len1 && j < len2) {
              if (L[i] < R[i]) {
                  arr[k] = L[i];
                  i++;
              } else {
                  arr[k] = R[i];
                  j++;
              }
              k++;
          }
  
          // add remaining elements
          while (i < len1) {
              arr[k] = L[i];
              i++;
              k++;
          }
  
          while (j < len2) {
              arr[k] = R[j];
              j++;
              k++;
          }
      }
  
      static class FastIO extends PrintWriter {
  		private InputStream stream;
  		private byte[] buf = new byte[1 << 16];
  		private int curChar, numChars;
  
  		// standard input
  		public FastIO() {
  			this(System.in, System.out);
  		}
  
  		public FastIO(InputStream i, OutputStream o) {
  			super(o);
  			stream = i;
  		}
  
  		// file input
  		public FastIO(String i, String o) throws IOException {
  			super(new FileWriter(o));
  			stream = new FileInputStream(i);
  		}
  
  		// throws InputMismatchException() if previously detected end of file
  		private int nextByte() {
  			if (numChars == -1)
  				throw new InputMismatchException();
  			if (curChar >= numChars) {
  				curChar = 0;
  				try {
  					numChars = stream.read(buf);
  				} catch (IOException e) {
  					throw new InputMismatchException();
  				}
  				if (numChars == -1)
  					return -1; // end of file
  			}
  			return buf[curChar++];
  		}
  
  		// to read in entire lines, replace c <= ' '
  		// with a function that checks whether c is a line break
  		public String next() {
  			int c;
  			do {
  				c = nextByte();
  			} while (c <= ' ');
  			StringBuilder res = new StringBuilder();
  			do {
  				res.appendCodePoint(c);
  				c = nextByte();
  			} while (c > ' ');
  			return res.toString();
  		}
  
  		public int nextInt() { // nextLong() would be implemented similarly
  			int c;
  			do {
  				c = nextByte();
  			} while (c <= ' ');
  			int sgn = 1;
  			if (c == '-') {
  				sgn = -1;
  				c = nextByte();
  			}
  			int res = 0;
  			do {
  				if (c < '0' || c > '9')
  					throw new InputMismatchException();
  				res = 10 * res + c - '0';
  				c = nextByte();
  			} while (c > ' ');
  			return res * sgn;
  		}
  
  		public double nextDouble() {
  			return Double.parseDouble(next());
  		}
  	}
  }
  