def gcd(a,b): if b==0: return a else: return gcd(b,a%b) T=int(input()) for _ in range(T): D,x,y=list(map(int,input().split())) if x==0: print(y*D) continue if y==0: print(x*D) continue t=gcd(max(x,y),min(x,y)) X=-y//t Y=x//t if ((not 0<=x-X <=D) or ((not 0<=y-Y <=D))) and ((not 0<=x+X <=D) or ((not 0<=y+Y <=D))): print(0) continue ans1=0 ans2=0 if (0<=x-X <=D) and (0<=y-Y <=D): ok=1 ng=D while abs(ok-ng)>1: m=(ng+ok)//2 if (0<=x-m*X <=D) and (0<=y-m*Y <=D): ok=m else: ng=m ans1=abs(x*(y-ok*Y)-y*(x-ok*X)) if (0<=x+X <=D) and (0<=y+Y <=D): ok=1 ng=D while abs(ok-ng)>1: m=(ng+ok)//2 if (0<=x+m*X <=D) and (0<=y+m*Y <=D): ok=m else: ng=m ans2=abs(x*(y+ok*Y)-y*(x+ok*X)) print(max(ans1,ans2))