q = int(input()) for _ in range(q): n, k = map(int, input().split()) ans = 0 v = 1 ev = 1 while v < n: ev *= k v += ev ans += 1 print(ans)