q = int(input()) for i in range(q): n, k = map(int, input().split()) ck = k use = k + 1 count = 1 while 1: if use >= n: print(count) break else: count += 1 ck *= k use += ck