#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll d, x, y; cin >> d >> x >> y; if (x == 0 || y == 0) { cout << max(x, y) * d << '\n'; return; } auto calc = [&](ll xi, ll yi) -> ll { ll res = (xi < x ? x * yi : xi * y) * 2; res -= x * y; res -= xi * yi; res -= abs(x - xi) * abs(yi - y); return res; }; ll g = __gcd(x, y); ll dx = y / g, dy = -(x / g); ll ans = 0; { ll k = min(x / dx, (d - y) / abs(dy)); if (k > 0) { ans = max(ans, calc(x - dx * k, y - dy * k)); } } { ll k = min((d - x) / dx, y / abs(dy)); if (k > 0) { ans = max(ans, calc(x + dx * k, y + dy * k)); } } cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; cin >> T; for (int t = 0; t < T; t++) { solve(); } return 0; }