rt
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fin for(int i=1;i<=n;i++)
const int N = 1e4 + 10;
const int inf = 0x3f;
const ll INF = 1e16;
int main() {
int n;
cin >> n;
fin {
int x, a, b;
cin >> x >> a >> b;
if (a > b)
cout << x << endl;
else if (b == 0) {
cout << x *min(a, 1) << endl;
continue;
} else if (a == b) {
if (x == 1)
cout << -b << endl;
else if (a == 1)
cout << -1 << endl;
else
cout << x << endl;
}
if (a == 1)
cout << x - ((x / b) + 1) *b << endl;
if (a * x - x - b < 0)
cout << x % (b - (a * x - x)) - (b - (a * x - x)) << endl;
else
cout << x << endl;
}
return 0;
}