import java.util.*; class Main3{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int q = sc.nextInt(); long[] n = new long[q]; long[] k = new long[q]; for(int i = 0; i < q; i++){ n[i] = sc.nextLong(); k[i] = sc.nextLong(); } for(int i = 0; i < q; i++){ if(k[i] == 1){ System.out.println(n[i]-1); }else{ int cou = 1; long tmp = k[i]; while(tmp < n[i]){ tmp*=k[i]; cou++; } System.out.println(cou); } } } }