/*** author: yuji9511 ***/ #include using namespace std; typedef long long ll; typedef pair lpair; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i void print(H&& h, T&&... t){cout<(t)...);} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll Q; cin >> Q; while(Q--){ ll N,K; cin >> N >> K; if(K == 1){ print(N-1); }else{ N -= 1; ll ans = 0; ll v = 1; while(N > 0){ ans++; N -= v; v *= K; } print(ans); } } }