#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL int main(){ int _t; cin>>_t; rep(_,_t){ long long D,a,b; cin>>D>>a>>b; long long ans = 0; { long long ok = 0,ng = Inf32; while(ng-ok>1LL){ long long mid = (ok+ng)/2; long long g= gcd(a,b); long long aa = a + (b/g)*mid; long long bb = b - (a/g)*mid; if(aa<0||aa>D||bb<0||bb>D){ ng = mid; } else ok = mid; } long long g = gcd(a,b); long long aa = a + (b/g)*ok; long long bb = b - (a/g)*ok; ans= max(ans,abs(aa*b-bb*a)); } { long long ok = 0,ng = Inf32; while(ng-ok>1LL){ long long mid = (ok+ng)/2; long long g= gcd(a,b); long long aa = a - (b/g)*mid; long long bb = b + (a/g)*mid; if(aa<0||aa>D||bb<0||bb>D){ ng = mid; } else ok = mid; } long long g = gcd(a,b); long long aa = a - (b/g)*ok; long long bb = b + (a/g)*ok; ans= max(ans,abs(aa*b-bb*a)); } cout<