import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int n = sc.nextInt(); long k = sc.nextInt(); int count = 0; long sum = 0; long base = 1; if (k == 1) { count = n; } else { while (sum < n) { count++; sum += base; base *= k; } } sb.append(count - 1).append("\n"); } System.out.print(sb); } }