#include using namespace std; int main(){ int Q; cin>>Q; for(int i=0;i>n>>k; if(k==1){ cout<=0){ n-=temp; temp*=k; cnt++; } cout<