#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int q; cin >> q; while (q--) { int n, k; cin >> n >> k; long long cur = 0, c = 1; for (int i = 0; ; i++) { cur += c; if (cur >= n) { cout << i << '\n'; break; } if (1. * c * k > 2e18) c = 1LL << 60; else c *= k; } } return 0; }