#include #define For(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) For(i, 0, n) #define rFor(i, a, b) for(int i = a; i >= b; i--) #define ALL(v) (v).begin(), (v).end() #define rALL(v) (v).rbegin(), (v).rend() using namespace std; using lint = long long; using ld = long double; int INF = 2000000000; lint LINF = 1000000000000000000; long long gcd(long long x, long long y) { if (y == 0) { return x; } return gcd(y, x % y); } int main() { int t; cin >> t; while (t--) { lint d, x, y; cin >> d >> x >> y; lint g = gcd(x, y); lint dx = x / g, dy = y / g; lint l = 0, r = 1000000010; while (r - l > 1) { lint mid = (l + r) / 2LL; lint nx = x - mid * dy, ny = y + mid * dx; if (0 <= nx && nx <= d && 0 <= ny && ny <= d) { l = mid; } else { r = mid; } } lint l2 = -1000000010, r2 = 0; while (r2 - l2 > 1) { lint mid = (l2 + r2) / 2LL; lint nx = x - mid * dy, ny = y + mid * dx; if (0 <= nx && nx <= d && 0 <= ny && ny <= d) { r2 = mid; } else { l2 = mid; } } lint dxy = dx * dx + dy * dy; cout << max(g * l * dxy, g * abs(r2) * dxy) << endl; } }