#include int ri() { int n; scanf("%d", &n); return n; } int main() { int q = ri(); for (int i = 0; i < q; i++) { int n = ri(); int k = ri(); if (k == 1) { std::cout << n - 1 << std::endl; } else { int res = -1; int cur = 1; int sum = 0; for (; sum < n; res++) { sum += cur; cur *= k; } std::cout << res << std::endl; } } return 0; }