为什么RE
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,x,a,b,y;
int main(){
cin >> t;
while(t--){
cin >> x >> a >> b;
if(a==1){
cout << x%b-b << endl;
continue;
}
while(1){
y=a*x-b;
if(y<0){
cout << y << endl;
break;
}else if(y>=x){
cout << x << endl;
break;
}
x=y;
}
}
}