#include using namespace std; using lint = long long int; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i> Q; REP(_, Q) { cin >> N >> K; lint ret = 0, a = 1; if (K == 1) { ret = N - 1; } else { while (a < N) ret++, a = a * K + 1; } cout << ret << endl; } }