import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int q = Integer.parseInt(br.readLine()); for (int i = 0; i < q; i++) { String[] sa = br.readLine().split(" "); long n = Integer.parseInt(sa[0]); long k = Integer.parseInt(sa[1]); if (k == 1) { System.out.println(n - 1); } else { long sum = 0; for (int j = 0; j < 40; j++) { long b = (long) Math.pow(k, j); sum += b; if (sum >= n) { System.out.println(j); break; } } } } br.close(); } }