#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int q; cin >> q; while (q--) { ll n, k; cin >> n >> k; if (k == 1) { cout << n - 1 << endl; continue; } ll ans = 0, now = 1, cnt = 1; while (cnt < n) { ans++; now *= k; cnt += now; } cout << ans << endl; } return 0; }