Q=int(input()) for i in range(Q): N,K=map(int,input().split()) summary=1 cnt=0 memo=1 while N>summary: memo*=K summary=summary+memo cnt+=1 print(cnt)