#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int x,a,b,t;
int main()
{
cin >> t;
while(t--)
{
cin >> x >> a >> b;
if(a*x-b<0)
{
cout << a*x-b << endl ;
continue;
}
else if(a==0||x==0)
{
cout << -b << endl ;
continue;
}
else if(a*x-b==0)
{
cout << -b << endl ;
continue;
}
else if(a*x-b>=x||b==0)
{
cout << x << endl ;
continue;
}
else
{
while(1)
{
x=a*x-b;
if(x<0)
{
cout << x << endl ;
break;
}
}
continue;
}
}
return 0;
}