#include using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair P; using VP = vector

; using VVP = vector; using VI = vector; using VVI = vector; using VVVI = vector; const int inf=1e9+7; const ll INF=1LL<<60; const ll Mod=998244353; void solve(ll a,ll b,ll c){ ll cnt=0; while(a>=2*c-1){ if(a%c!=0){ a=a/c; cnt+=2; } else{ a=a/c; cnt++; } } if(a==0) cnt+=0; else if(a<=c-1) cnt++; else cnt+=2; cout<>q; for(int l=0;l>a>>b>>c; solve(a,b,c); } }