#include using namespace std; using ll = long long; ll solve(ll n, ll K) { if (K == 1) return n - 1; ll ans = 0; __int128_t hoge = K; while (true) { __int128_t foo = (hoge - 1) / (K - 1); if (foo >= n) { break; } ans++; hoge *= K; } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int q; cin >> q; for (int i = 0; i < q; i++) { ll n, K; cin >> n >> K; cout << solve(n, K) << "\n"; } return 0; }