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 javax.naming.PartialResultException;
  import java.io.Closeable;
  import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.Arrays;
  
  public class B {
      public static void main(String[] args) throws IOException {
          FastScanner scanner = new FastScanner();
          int[] powers = new int[20];
          for (int i = 0; i < powers.length; i++) powers[i] = 1 << i;
          int t = scanner.nextInt();
          while (t-- > 0) {
              int l = scanner.nextInt();
              int r = scanner.nextInt();
              int lp = Arrays.binarySearch(powers, l);
              if (lp < 0) lp = - (lp + 1) - 1;
              int rp = Arrays.binarySearch(powers, r);
              if (rp < 0) rp = - (rp + 1) - 1;
              if (lp == rp) {
                  System.out.println(0);
                  continue;
              }
  
              int[] zeroCounters = new int[rp + 1];
  
              for (int i = 0; i < zeroCounters.length; i++) {
                  int period = 1 << (i + 1);
                  int begin = l / period;
                  if (l % period != 0) begin++;
                  begin *= period;
                  int n = r - begin + 1;
  
                  if (n > 0) {
                      zeroCounters[i] = n / period * (period >> 1);
                      zeroCounters[i] += Math.min(period >> 1, n % period);
                      zeroCounters[i] += Math.max(0, (begin - l) - (period >> 1));
                  } else {
                      zeroCounters[i] = Math.min(period >> 1, r % period);
                      zeroCounters[i] -= Math.min(period >> 1, l % period);
                  }
              }
  //            for (int i = lp; i <= r; i++) {
  //                for (int j = 0; j < zeroCounters.length; j++) {
  //                    if (((1 << j) & i) == 0) zeroCounters[j]++;
  //                }
  //            }
              System.out.println(Arrays.stream(zeroCounters).min().getAsInt());
          }
      }
  
      /**
       * Credits: https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
       */
      private static class FastScanner implements Closeable {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public FastScanner() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public FastScanner(String file_name) throws IOException {
              din = new DataInputStream(new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public String readLine() throws IOException {
              byte[] buf = new byte[64];
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n' || c == '\r') {
                      if (cnt != 0) {
                          break;
                      } else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          public String next() throws IOException {
              return next(32);
          }
  
          public String next(int len) throws IOException {
              byte[] buf = new byte[len];
              int ptr = 0;
              byte c = read();
              while (c <= ' ') c = read();
              do {
                  if (ptr == buf.length) {
                      buf = Arrays.copyOf(buf, buf.length << 1);
                  }
                  buf[ptr++] = c;
              } while ((c = read()) > ' ');
              if (buf.length == ptr) return new String(buf);
              return new String(Arrays.copyOf(buf, ptr));
          }
  
          public int nextInt() throws IOException {
              int ret = 0;
              byte c = read();
              while (c <= ' ') c = read();
              boolean neg = (c == '-');
              if (neg) c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg) return -ret;
              return ret;
          }
  
          public long nextLong() throws IOException {
              long ret = 0;
              byte c = read();
              while (c <= ' ') c = read();
              boolean neg = (c == '-');
              if (neg) c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg) return -ret;
              return ret;
          }
  
          public double nextDouble() throws IOException {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ') c = read();
              boolean neg = (c == '-');
              if (neg) c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
              if (neg) return -ret;
              return ret;
          }
  
          private void fillBuffer() throws IOException {
              bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
              if (bytesRead == -1) buffer[0] = -1;
          }
  
          private byte read() throws IOException {
              if (bufferPointer == bytesRead) fillBuffer();
              return buffer[bufferPointer++];
          }
  
          @Override
          public void close() throws IOException {
              if (din == null) return;
              din.close();
          }
      }
  }
  