#include using namespace std; int main(){ int Q; cin >> Q; while (Q--){ long long N, K; cin >> N >> K; if (K == 1){ cout << N - 1 << '\n'; }else{ long long depth = 0; long long c = 1; while (N > 0){ ++depth; N -= c; c *= K; } cout << depth - 1 << '\n'; } } return 0; }