#include using namespace std; using ll = long long; void solve() { ll D, x, y; cin >> D >> x >> y; if(x == 0 && y == 0) { cout << 0 << endl; } else if(x == 0) { cout << y * D << endl; } else if(y == 0) { cout << x * D << endl; } else { if(x < y) swap(x, y); const ll g = gcd(x, y); const ll p = x / g; const ll q = y / g; const ll a = x / q; const ll b = (D - y) / p; cout << (p * p + q * q) * g * min(a, b) << endl; } } int main() { int T; cin >> T; while(T--) solve(); }