#include #include #include #include #include #include #include #include #include #include using namespace std; #define MOD 1000000007 #define INF (1<<29) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long Int; typedef pair P; Int n, k, q; int main(){ cin >> q; for(int i = 0;i < q;i++){ cin >> n >> k; if(k == 1)cout << n-1 << endl; else{ Int floor = 1; Int now = 1; Int ans = 0; while(now < n){ floor *= k; now += floor; ans++; } cout << ans << endl; } } return 0; }