#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; auto floor_div(signed_integral auto x, signed_integral auto y) { return x / y - ((x ^ y) < 0 && x % y != 0); } template T floor_div(T x, unsigned_integral auto y) { return x >= 0 ? T(x / y) : -T(-x / y + (-x % y != 0)); } auto ceil_div(signed_integral auto x, signed_integral auto y) { return x / y + ((x ^ y) >= 0 && x % y != 0); } template T ceil_div(T x, unsigned_integral auto y) { return x >= 0 ? T(x / y + (x % y != 0)) : -T(-x / y); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int d, x, y; cin >> d >> x >> y; int g = gcd(x, y); int dx = -y / g, dy = x / g; int l = -d, r = d; // 0 <= x + i*dx <= d // (x-d)/(-dx) <= i <= x/(-dx) if (dx) { chmax(l, ceil_div(x - d, -dx)); chmin(r, floor_div(x, -dx)); } // 0 <= y + i*dy <= d // -y/dy <= i <= (d-y)/dy if (dy) { chmax(l, ceil_div(-y, dy)); chmin(r, floor_div(d - y, dy)); } assert(l <= 0 && 0 <= r); ll ans = ((ll)dx * dx + (ll)dy * dy) * (max(x, y) / max(-dx, dy)) * max(-l, r); cout << ans << '\n'; } }