#include #include #include #include #include long long solve() { long long D, X, Y; std::cin >> D >> X >> Y; long long g{std::gcd(X, Y)}; long long ans{}; { long long x{-Y / g}, y{X / g}; long long ok{}, ng{D + 1}; while (ng - ok > 1) { long long mid{(ok + ng) / 2}; long long p{X + x * mid}, q{Y + y * mid}; if (0 <= p and p <= D and 0 <= q and q <= D) { ok = mid; } else { ng = mid; } } long long p{X + x * ok}, q{Y + y * ok}; long long area{std::abs(X * q - Y * p)}; ans = std::max(ans, area); } { long long x{Y / g}, y{-X / g}; long long ok{}, ng{D + 1}; while (ng - ok > 1) { long long mid{(ok + ng) / 2}; long long p{X + x * mid}, q{Y + y * mid}; if (0 <= p and p <= D and 0 <= q and q <= D) { ok = mid; } else { ng = mid; } } long long p{X + x * ok}, q{Y + y * ok}; long long area{std::abs(X * q - Y * p)}; ans = std::max(ans, area); } return ans; } int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int T; std::cin >> T; while (T--) std::cout << solve() << '\n'; }