import math def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok T=int(input()) for t in range(T): D,X,Y=map(int,input().split()) g=math.gcd(X,Y) x=X//g y=Y//g def is_ok(c): return X+c*y<=D and Y-c*x>=0 inf=1<<30 r=Bisect_Int(-inf,inf,is_ok) def is_ok(c): return X+c*y>=0 and Y-c*x<=D l=Bisect_Int(inf,-inf,is_ok) if l>r or l==r==0: ans=0 else: ans=max(abs(l),abs(r))*(X*x+Y*y) print(ans)