#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; int main() { int t; cin >> t; while (t--) { lint d, x, y; cin >> d >> x >> y; lint l = 0, r = 1000000010; while (r - l > 1) { lint mid = (l + r) / 2LL; lint nx = x - mid * y, ny = y + mid * x; 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 * y, ny = y + mid * x; if (0 <= nx && nx <= d && 0 <= ny && ny <= d) { r2 = mid; } else { l2 = mid; } } lint x2 = x - l * y, y2 = y + l * x; lint x3 = x - r2 * y, y3 = y + r2 * x; auto dist = [&](lint p, lint q) -> lint { return abs(p - x) * abs(p - x) + abs(q - y) * abs(q - y); }; cout << max(dist(x2, y2), dist(x3, y3)) << endl; } }