#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} void solve(){ long long d, ax, ay; cin >> d >> ax >> ay; long long g = gcd(ax, ay); long long k_max = 0; long long k_min = 0; auto get_max = [&](long long dx, long long dy){ long long ok = 0, ng = 1001001001; while(ng - ok > 1){ long long mid = (ok + ng) / 2; long long bx = ax + dx * mid; long long by = ay + dy * mid; if(0 <= bx && bx <= d && 0 <= by && by <= d) ok = mid; else ng = mid; } return ok; }; k_max = get_max(-ay / g, ax / g); k_min = -get_max(ay / g, -ax / g); long long ans = max(k_max, -k_min) * g * ((ax / g) * (ax / g) + (ay / g) * (ay / g)); cout << ans << "\n"; } int main(){ int t; cin >> t; while(t--) solve(); return 0; }