#include #include #include using namespace std; void solve() { long long d, x, y; cin >> d >> x >> y; if (x == 0 || y == 0) { cout << max(x, y) * d << endl; return; } int g = abs(__gcd(x, y)); long long ans = 0; { long long dx = y / g, dy = - x / g; int k = min(x / dx, (d - y) / (-dy)); long long nx = x + dx * k, ny = y + dy * k; ans = max(ans, (long long)abs(nx * y - ny * x)); } { long long dx = - y / g, dy = x / g; int k = min(y / dy, (d - x) / (-dx)); long long nx = x + dx * k, ny = y + dy * k; ans = max(ans, (long long)abs(nx * y - ny * x)); } cout << ans << endl; } int main() { int t; cin >> t; while (t--) solve(); }