#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int lint; typedef pair IP; typedef pair LLP; typedef pairCP; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define sort(v) sort((v).begin(), (v).end()) #define reverse(v) reverse((v).begin(), (v).end()) #define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge) #define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge) #define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge) #define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge) int main() { lint Q; cin >> Q; rep(i, Q) { lint N, K; cin >> N >> K; lint ans = 0; if (K == 1) { ans = N - 1; } else { lint now = 1; lint sum = 1; lint cnt = 0; while (1) { if (now >= N) { ans = cnt; break; } sum *= K; now += sum; cnt++; } } cout << ans << endl; } }