#include using namespace std; typedef long long ll; typedef pair ii; int main() { ios::sync_with_stdio(false); cin.tie(0); ll q, n, k; cin >> q; for (int ctr1 = 0; ctr1 < q; ++ctr1) { cin >> n >> k; if (k == 1) { cout << n - 1 << "\n"; continue; } ll cur = 1, rez = 0; while (n > cur) { n -= cur; cur *= k; ++rez; } cout << rez << "\n"; } return 0; }