#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define ll long #define rep(i, m, n) for (ll i = m; i < n; i++) #define rrep(i, m, n) for (ll i = m - 1; i >= n; i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(), N.end()), N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(), n.end()) #define HOUT(S) cout << setprecision(50) << S << endl #define pint pair #define tint tuple #define endl "\n" #define mod 1000000007LL #define MAX 100010LL #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value != 0>::type fill_v(U& u, const V... v) { u = U(v...); } template typename enable_if::value == 0>::type fill_v(U& u, const V... v) { for (auto& e : u) fill_v(e, v...); } long long gcd (long long num1, long long num2) { long long k = min (__builtin_ctzl(num1), __builtin_ctzl(num2)); num1 >>= __builtin_ctzl(num1); num2 >>= __builtin_ctzl(num2); while (num1 != num2) { if (num1 > num2) { num1 -= num2; num1 >>= __builtin_ctzl(num1); } else { num2 -= num1; num2 >>= __builtin_ctzl(num2); } } return num1 << k; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll t; ll d, x, y; cin >> t; while(t--) { cin >> d >> x >> y; ll g = gcd(x, y); ll u = x / g; ll v = y / g; ll ans = 0; if(v) { ll n = (d - x) / v; if(y - n * u >= 0) chmax(ans, (x * x + y * y) * n / g); ll m = x / v; if(y + m * u <= d) chmax(ans, (x * x + y * y) * m / g); } if(u) { ll n = (d - y) / u; if(x - n * v >= 0) chmax(ans, (x * x + y * y) * n / g); ll m = y / u; if(x + m * v <= d) chmax(ans, (x * x + y * y) * m / g); } cout << ans << endl; } }