Q=int(input()) for _ in range(Q): n,k=map(int,input().split()) if k==1: print(n-1) else: c=1 for i in range(100): if n<=c: print(i) break c+=c*k