#include typedef long long ll; using namespace std; #define all(x) (x).begin(), (x).end() #define MOD 1000000007 int main() { int q; cin >> q; while(q--) { ll n, k; cin >> n >> k; if(k == 1) { cout << n - 1 << endl; } else { ll mul = 1, cum = 1; ll ans = 0; while(cum < n) { mul *= k; cum += mul; ans++; } cout << ans << endl; } } }