#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll = long long; int main() { int Q; cin >> Q; while (Q--) { ll N, K; cin >> N >> K; ll cnt = 0; ll siz = 1; while (N > 0) { N -= siz; siz *= K; cnt++; } cout << cnt - 1 << endl; } return 0; }