#include #include #include #include #include using ll = long long; using namespace std; int main() { int q; cin >> q; while (q--) { long n, k; cin >> n >> k; long d = -1, pow = 1; while (n > 0) { n -= pow; pow *= k; d++; } cout << d << '\n'; } return 0; }