if __name__ == "__main__": Q = int(input()) for _ in range(Q): n, k = map(int, input().split()) if k == 1: print(n - 1) else: dep = 0 now = 1 while now < n: now += k ** (dep + 1) dep += 1 print(dep)