#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void solve() { long long d, x, y; cin >> d >> x >> y; long long dx = x, dy = y; long long g = gcd(x, y); x /= g; y /= g; long long ok_h = 0, ng_h = d + 1; auto is_ok = [&](long long h) -> bool { long long xx = x + h * dy; long long yy = y - h * dx; return xx >= 0 && yy >= 0 && xx <= d && yy <= d; }; while (ok_h + 1 < ng_h) { long long mid = (ok_h + ng_h) / 2; if (is_ok(mid)) { ok_h = mid; } else { ng_h = mid; } } long long ng_l = -d - 1, ok_l = 0; while (ng_l + 1 < ok_l) { long long mid = (ng_l + ok_l) / 2; if (is_ok(mid)) { ok_l = mid; } else { ng_l = mid; } } long long ans = 0; { long long xx = x + ok_h * dy; long long yy = y - ok_h * dx; ans = max(ans, abs(xx * y - yy * x)); } { long long xx = x + ok_l * dy; long long yy = y - ok_l * dx; ans = max(ans, abs(xx * y - yy * x)); } cout << ans << "\n"; } int main() { fast_io(); int t; cin >> t; for (; t--;) { solve(); } }