/* -*- coding: utf-8 -*- * * 897.cc: No.897 compç•™ctree - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { int q; scanf("%d", &q); while (q--) { int n, k; scanf("%d%d", &n, &k); int d = 0; if (k == 1) d = n - 1; else { ll e = 1; while (n > e) { d++; n -= e; e *= k; } } printf("%d\n", d); } return 0; }