#include using namespace std; typedef long long int ll; int Q; int N, K; int main(){ cin >> Q; for(int i = 0; i < Q; i++){ cin >> N >> K; if(K == 1){ cout << N - 1 << endl; continue; } ll sum = 1; ll powK = 1; int res = 0; for(;;){ if(sum >= N) break; sum += powK; powK *= K; res++; } cout << res << endl; } return 0; }