#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; ll cur = 1, rez = 0; while (n > cur) { n -= cur; cur *= k; ++rez; } cout << rez << "\n"; } return 0; }