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: //jai Shree Krishna
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.util.Collections;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.OutputStreamWriter;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  public class B{
  // author: Tarun Verma
  	static FastScanner sc = new FastScanner();
  	static int inf = Integer.MAX_VALUE;
  	static long mod = 1000000007;
  	static BufferedWriter output = new BufferedWriter(
  			new OutputStreamWriter(System.out));
  	static PrintWriter out=new PrintWriter(System.out);
  	/* Common Mistakes By Me
  	 * make sure to read the bottom part of question
  	 * special cases (n=1?)
  	 * In Game Theory Check your solution and consider all the solutions
  	 * Always initialise value to the declare array in local scope
  	 * don't use debugs in interactive problems
  	 * Always Reset vis,adj array upto n+1 otherwise can cause TLE
  	 */
  	public static void solve() {
  		long n = sc.nextLong();
  		long k = sc.nextLong();
  		long last = -1l;
  		long last2 = -1;
  		for(long i = 63;i>=0;i--) {
  			if(((1l << i) & k) != 0) {
  				last = i;
  				break;
  			}
  		}
  		for(long i = 63;i>=0;i--) {
  			if(((1l << i) & n) != 0) {
  				last2 = i;
  				break;
  			}
  		}
  		
  //		System.out.println("last: " + last);
  //		System.out.println("req: " + req);
  //		System.out.println(last);
  		long sum = 0;
  		sum += min(last+1, last2);
  		long req = (1l << min(last+1, last2));
  		n -= req;
  		sum += (n / k);
  		n = n % k;
  		if(n != 0) {
  			sum ++;
  		}
  		System.out.println(sum);
  		
  		
  	}
  	public static void main(String[] args) {
  		int t = 1;
  		t = sc.nextInt();
  		outer: for (int tt = 0; tt < t; tt++) {
  			solve();
  		}
  	}
  	
  ////////////////////////////////////////////////////////////////////////////////////
  ////////////////////DO NOT BELOW THIS LINE //////////////////////////////////
  ////////////////////////////////////////////////////////////////////////////////////
  	
  	static int max(int a, int b) { return Math.max(a, b);} 
  	static int min(int a, int b) {return Math.min(a, b);}
  	static long max(long a, long b){return Math.max(a, b);}
  	static long min(long a, long b) {return Math.min(a, b);}
  	static void sort(int arr[]) {
  		ArrayList<Integer> a = new ArrayList<Integer>();
  		for(int i: arr) a.add(i);
  		Collections.sort(a);
  		for(int i=0;i<arr.length;i++) arr[i] = a.get(i);
  	}
  	static void sort(long arr[]) {
  		ArrayList<Long> a = new ArrayList<Long>();
  		for(long i: arr) a.add(i);
  		Collections.sort(a);
  		for(int i=0;i<arr.length;i++) arr[i] = a.get(i);
  	}
  	static int abs(int a) {return Math.abs(a);}
  	static long abs(long a) {return Math.abs(a);}
  	static int gcd(int a, int b) {
  		if (b == 0)
  			return a;
  		return gcd(b, a % b);
  	}
  	static long gcd(long a, long b) {
  		if (b == 0)
  			return a;
  		return gcd(b, a % b);
  	}
  	
  	static class FastScanner {
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st = new StringTokenizer("");
  		
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			return st.nextToken();
  		}
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		int[] readArray(int n) {
  			int[] a = new int[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextInt();
  			return a;
  		}
  		long[] readLongArray(int n) {
  			long[] a = new long[n];
  			for (int i = 0; i < n; i++)
  				a[i] = nextLong();
  			return a;
  		}
  		
  		int[][] read2dArray(int n, int m) {
  			int arr[][] = new int[n][m];
  			for (int i = 0; i < n; i++) {
  				for (int j = 0; j < m; j++) {
  					arr[i][j] = nextInt();
  				}
  			}
  			return arr;
  		}
  		
  		ArrayList<Integer> readArrayList(int n) {
  			ArrayList<Integer> arr = new ArrayList<Integer>();
  			for (int i = 0; i < n; i++) {
  				int a = nextInt();
  				arr.add(a);
  			}
  			return arr;
  		}
  		
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
  	
  	static class pair {
  		int fr, sc;
  		
  		pair(int fr, int sc) {
  			this.fr = fr;
  			this.sc = sc;
  		}
  	}
  	
  ////////////////////////////////////////////////////////////////////////////////////	
  	
  }
  