#include using namespace std; using ll = long long; using P = pair; #define rep(i,n) for(int i=0;i> q; rep(i,q){ int n,k; cin >> n >> k; if (k==1){ cout << n-1 << endl; continue; } int ans = 0; while (n>=0){ ans++; n -= pow(k,ans); } cout << ans << endl; } return 0; }