#include #define int long long using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } int solve(int N,int K) { if(K==1) return N-1; int x=1; for(int i=0;;i++){ N-=x; if(N<=0) return i; x*=K; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); int Q; cin>>Q; while(Q--){ int N,K; cin>>N>>K; cout<