#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll D, x, y, ans = 0; cin >> D >> x >> y; auto calc = [&](ll x2, ll y2){ ans = max(ans, abs(x * y2 - y * x2)); }; ll g = gcd(x, y); if(g == 0){ cout << 0 << '\n'; continue; } ll dx = y / g, dy = x / g; ll d = min(x / dx, (D - y) / dy); calc(x - dx * d, y + dy * d); d = min((D - x) / dx, y / dy); calc(x + dx * d, y - dy * d); cout << ans << '\n'; } }