#include<bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int main()
{
int t;
cin >> t;
while(t--){
int x, a, b;
cin >> x >> a >> b;
int last;
last = x;
bool if_s = false;
while(x >= 0){
x = (a * x) - b;
if(last <= x){
cout << last << endl;
if_s = true;
break;
}
last = x;
}
if(!if_s){
cout << last << endl;
}
}
return 0;
}