#include using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=100003,INF=1<<30; int main(){ int Q;cin>>Q; while(Q--){ ll A,B,C;cin>>A>>B>>C; int cnt=0; while(A){ if(A%C){ A-=A%C; cnt++; }else{ A/=C; cnt++; } } cout<