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 tmp = 1 while now < n: tmp *= k now += tmp dep += 1 print(dep)