#include using namespace std; int main() { ios::sync_with_stdio(false); int Q; cin >> Q; while (Q--) { int N, K; cin >> N >> K; if (K == 1) { cout << N - 1 << endl; } else { int64_t s = 0; int64_t pk = 1; for (int i = 0; ; ++i) { s += pk; pk *= K; if (s >= N) { cout << i << endl; break; } } } } return 0; }