#include using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair; using PLL = pair; const double eps = 1e-10; templateinline void chmin(A &a, B b){if(a > b) a = b;} templateinline void chmax(A &a, B b){if(a < b) a = b;} template vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template typename enable_if::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v(e,v...); } class FFT { public: using Real = double; using Complex = std::complex; using size_type = std::size_t; private: static Complex mul(const Complex& a, const Complex& b) { return Complex(real(a)*real(b)-imag(a)*imag(b), real(a)*imag(b)+real(b)*imag(a)); } static void fft(std::vector &a, bool inv = false) { std::int64_t n = a.size(); std::vector tmp(n); std::int64_t mask = n - 1; std::int64_t h_bit = n >> 1; // highest-bit for (std::int64_t k = 1, l = mask; l > 0; k++, l >>= 1) { Complex e = std::polar(1.0, 2 * M_PI / (1 << k) * (inv ? -1 : 1)); Complex zeta =1; for (std::int64_t i = 0; i <= mask; i++) { std::int64_t idx = ((i >> k) << (k - 1)) | (i & ((1 << (k - 1)) - 1)); tmp[i] = a[idx] + mul(zeta, a[h_bit | idx]); zeta = mul(zeta, e); } std::swap(a, tmp); } if (inv) { for (std::int64_t i = 0; i < n; i++) { a[i] /= n; } } } public: static std::vector conv(const std::vector& ar, const std::vector& br) { size_type deg = ar.size() + br.size() - 1; size_type n = 1; while (n < deg) n <<= 1; std::vector a(n, 0); for (std::int64_t i = 0; i < ar.size(); i++) a[i].real(ar[i]); for (std::int64_t i = 0; i < br.size(); i++) a[i].imag(br[i]); std::vector c(n); fft(a); for (std::int64_t i = 0; i < n; i++) { c[i] = mul(mul(a[i] + conj(a[(n - i)%n]), a[i] - conj(a[(n - i)%n])), Complex(0, -0.25)); } fft(c, 1); std::vector cr(n); for (std::int64_t i = 0; i < deg; i++) { cr[i] = std::round(c[i].real()); } return cr; } }; namespace ArbitraryModFFT { using Real = double; using Complex = std::complex; using size_type = std::size_t; static Complex mul(const Complex& a, const Complex& b) { return Complex(real(a)*real(b)-imag(a)*imag(b), real(a)*imag(b)+real(b)*imag(a)); } static void fft(std::vector &a, bool inv = false) { std::int64_t n = a.size(); std::vector tmp(n); std::int64_t mask = n - 1; std::int64_t h_bit = n >> 1; // highest-bit for (std::int64_t k = 1, l = mask; l > 0; k++, l >>= 1) { double deg = 2 * M_PI / (1 << k) * (inv ? -1 : 1); Complex e = Complex(cosl(deg), sinl(deg)); Complex zeta =1; for (std::int64_t i = 0; i <= mask; i++) { std::int64_t idx = ((i >> k) << (k - 1)) | (i & ((1 << (k - 1)) - 1)); tmp[i] = a[idx] + mul(zeta, a[h_bit | idx]); zeta = mul(zeta, e); } std::swap(a, tmp); } if (inv) { for (std::int64_t i = 0; i < n; i++) { a[i] /= n; } } } static std::vector conv(const std::vector& ar, const std::vector& br) { size_type deg = ar.size() + br.size() - 1; size_type n = 1; while (n < deg) n <<= 1; std::vector a(n, 0); for (std::int64_t i = 0; i < ar.size(); i++) a[i].real(ar[i]); for (std::int64_t i = 0; i < br.size(); i++) a[i].imag(br[i]); std::vector c(n); fft(a); for (std::int64_t i = 0; i < n; i++) { c[i] = mul(mul(a[i] + conj(a[(n - i)%n]), a[i] - conj(a[(n - i)%n])), Complex(0, -0.25)); } fft(c, 1); std::vector cr(n); for (std::int64_t i = 0; i < deg; i++) { cr[i] = std::round(c[i].real()); } return cr; } } int main(void){ int64 Q; cin >> Q; REP(_, Q) { int64 N, K; cin >> N >> K; int64 res = 0; if (K == 1) { cout << N-1 << endl; continue; } while (N) { res++; N = (N+K-2) / K; } cout << res-1 << endl; } }