#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ long long D; cin >> D; long long x,y; cin >> x >> y; if(y == 0) swap(x,y); if(x == 0){ cout << y*D << "\n"; continue; } long long g = gcd(x,y); long long dx = x/g,dy = y/g,answer = 0; long long v = min(x/dy,(D-y)/dx); long long v2 = min((D-x)/dy,y/dx); answer = max(g*v,g*v2); x /= g; y /= g; answer *= x*x+y*y; cout << answer << "\n"; } }