#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 <= 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 { int dep = 0; i64 tmp = 1; const i64 T = (i64)n * (i64)(k - 1) + 1; while(tmp < T) { tmp *= k; dep++; } printf("%d\n", dep - 1); } } return 0; } // Θ(ON)