// yukicoder: No.897 compαctree // 2019.10.5 bal4u #include typedef long long ll; int main() { int N, K, Q, ans; ll k, s; scanf("%d", &Q); while (Q--) { scanf("%d%d", &N, &K); s = 1, k = 1, ans = 0; while (s < N) k *= K, s += k, ans++; printf("%d\n", ans); } return 0; }