q = int(input()) for i in range(q): n, k = map(int, input().split()) if n == 1: print(0) elif k == 1: print(n - 1) else: total =1 depth = 0 term = 1 while total < n: depth += 1 term *= k total += term print(depth)