#include using namespace std; #define int long long signed main(){ int q;cin>>q; while(q--){ int a,b,c;cin>>a>>b>>c; int ans=0; while(a){ if(ac&&a<=2*(c-1)){ans+=2;break;} if(a%c)ans++; a/=c;ans++; } cout<