description: Berland State University has received a new update for the operating system. Initially it is installed only on the 1-st computer.
  
  Update files should be copied to all n computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.
  
  Your task is to find the minimum number of hours required to copy the update files to all n computers if there are only k patch cables in Berland State University.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases.
  
  Each test case consists of a single line that contains two integers n and k (1 ≤ k ≤ n ≤ 10^{18}) — the number of computers and the number of patch cables.
  
  Output
  
  For each test case print one integer — the minimum number of hours required to copy the update files to all n computers.
  
  Example
  
  Input
  
  
  4
  8 3
  6 6
  7 1
  1 1
  
  
  Output
  
  
  4
  3
  6
  0
  
  Note
  
  Let's consider the test cases of the example:
  
    * n=8, k=3: 
      1. during the first hour, we copy the update files from the computer 1 to the computer 2; 
      2. during the second hour, we copy the update files from the computer 1 to the computer 3, and from the computer 2 to the computer 4; 
      3. during the third hour, we copy the update files from the computer 1 to the computer 5, from the computer 2 to the computer 6, and from the computer 3 to the computer 7; 
      4. during the fourth hour, we copy the update files from the computer 2 to the computer 8. 
    * n=6, k=6: 
      1. during the first hour, we copy the update files from the computer 1 to the computer 2; 
      2. during the second hour, we copy the update files from the computer 1 to the computer 3, and from the computer 2 to the computer 4; 
      3. during the third hour, we copy the update files from the computer 1 to the computer 5, and from the computer 2 to the computer 6. 
    * n=7, k=1: 
      1. during the first hour, we copy the update files from the computer 1 to the computer 2; 
      2. during the second hour, we copy the update files from the computer 1 to the computer 3; 
      3. during the third hour, we copy the update files from the computer 1 to the computer 4; 
      4. during the fourth hour, we copy the update files from the computer 4 to the computer 5; 
      5. during the fifth hour, we copy the update files from the computer 4 to the computer 6; 
      6. during the sixth hour, we copy the update files from the computer 3 to the computer 7. 
solution: 
  import java.io.DataInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  public class EduB {
      private static long solve(long n, long k) {
          if (n == 1)
              return 0;
          if (k == 1)
              return n - 1l;
  
          long hours = 1l;
          long pow = 1l;
          long covered = 1l;  // covered after 1st installation
  
          while (pow * 2l <= k && covered + (pow * 2l) < n) {
              hours++;
              pow <<= 1l;
              covered += pow;
          }
  
          if (covered < n) {
  
              long l = n - covered - 1l;
              long ans = (l%k==0)? l/k : (l+k)/k;
              return ans + hours;
          }
  
          return hours;
      }
  
      public static void main(String[] args)
              throws IOException {
          Scanner s = new Scanner();
          int t = 1;
          t = s.nextInt();
          StringBuilder ans = new StringBuilder();
          int count = 0;
          while (t-- > 0) {
              long n = s.nextLong();
              long m = s.nextLong();
              ans.append(solve(n, m)).append("\n");
          }
          System.out.println(ans.toString());
      }
  
      static class Scanner {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
  
          public Scanner() {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
  
          public Scanner(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]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      } else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte) c;
              }
              return new String(buf, 0, cnt);
          }
  
          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++];
          }
  
          public void close() throws IOException {
              if (din == null)
                  return;
              din.close();
          }
      }
  
      public static long norm(long a, long MOD) {
          return ((a % MOD) + MOD) % MOD;
      }
  
      public static long msub(long a, long b, long MOD) {
          return norm(norm(a, MOD) - norm(b, MOD), MOD);
  
      }
  
      public static long madd(long a, long b, long MOD) {
          return norm(norm(a, MOD) + norm(b, MOD), MOD);
  
      }
  
      public static long mMul(long a, long b, long MOD) {
          return norm(norm(a, MOD) * norm(b, MOD), MOD);
  
  
      }
  
      public static long mDiv(long a, long b, long MOD) {
          return norm(norm(a, MOD) / norm(b, MOD), MOD);
      }
  
      public static String formattedArray(int a[]) {
          StringBuilder res = new StringBuilder("");
          for (int e : a)
              res.append(e).append(" ");
          return res.toString().trim();
  
      }
  
      private static void getInputs(Scanner s, int[] a, int n) throws IOException {
          for (int i = 0; i < n; i++) {
              a[i] = s.nextInt();
          }
      }
  }
  