#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; vector n(q); vector k(q); rep(i, q) cin >> n[i] >> k[i]; rep(i, q) { int res = 1; int ans = 0; int sol = n[i]; while (1) { sol = sol - res; res *= k[i]; if (sol > 0) ans++; else break; } cout << ans << endl; } }