#include using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a,Ts... ts){ return std::vector(ts...))>(a,make_v(ts...)); } int main() { int q; scanf("%d", &q); assert(1 <= q and q <= (int)10); while(q--) { int n, k; scanf("%d%d", &n, &k); assert(1 <= n and n <= (int)1e9); assert(1 <= k and k <= (int)1e9); if(k == 1) printf("%d\n", n - 1); else { i64 dep = 0, now = 1, tmp = 1; while(now < n) { tmp *= (i64)k; now += tmp; dep++; } printf("%d\n", dep); } } return 0; } // Θ(Qlog_K(N))