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