#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(int i=0;i> T; while(T--){ ll D,a,b; cin >> D >> a >> b; if(a==0){ cout << b*D << endl; continue; } if(b==0){ cout << a*D << endl; continue; } ll x,y; ll c=a*a+b*b; ll g=extgcd(a,b,x,y); if(c%g!=0){ cout << 0 << endl; continue; } double p=-1.0*c*x/b,q=1.0*(D*g-c*x)/b; double pp=1.0*(c*y-D*g)/a,qq=1.0*c*y/a; if(max(p,pp)>min(q,qq)){ cout << 0 << endl; continue; } ll u=(ll)(max(p,pp)),v=(ll)(min(q,qq)); ll X,Y,s=0,S=0; for(i=u-1;i<=u+1;i++){ X=c*x/g+b*i/g; Y=c*y/g-a*i/g; if(!(X>=0 && X<=D)) continue; if(!(Y>=0 && Y<=D)) continue; s=max(s,2*max(a,X)*max(b,Y)-(a*b+X*Y+llabs(X-a)*llabs(Y-b))); } for(i=v-1;i<=v+1;i++){ X=c*x/g+b*i/g; Y=c*y/g-a*i/g; if(!(X>=0 && X<=D)) continue; if(!(Y>=0 && Y<=D)) continue; S=max(S,2*max(a,X)*max(b,Y)-(a*b+X*Y+llabs(X-a)*llabs(Y-b))); } cout << max(s,S) << endl; } return 0; }