import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines Q = int(readline()) m = map(int,read().split()) NK = zip(m,m) def solve(N,K): if K == 1: return N - 1 dep = 0 v = 1 last_v = 1 while True: if v >= N: return dep last_v *= K v += last_v dep += 1 # [solve(n,k) for n,k in [(4,2), (41,3), (100,1)]] answer = [solve(n,k) for n,k in NK] print('\n'.join(map(str,answer)))