#include using namespace std; const long long INF = 1e18; long gcd(long n1, long n2) { long ret = n1 % n2; return (ret == 0) ? n2 : gcd(n2, ret); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin>>T; while(T--) { long x, y, D; cin>>D>>x>>y; long ans = 0; long X = x / gcd(x, y); long Y = y / gcd(x, y); { long mt = min((D-y)/X, x/Y); long i = y+mt*X; long j = x-mt*Y; ans = max(ans, abs(x*i - y*j)); } { long mt = min((D-x)/Y, y/X); long i = y-mt*X; long j = x+mt*Y; ans = max(ans, abs(x*i - y*j)); } cout<