import sys input = sys.stdin.readline from math import gcd T=int(input()) for tests in range(T): D,x,y=map(int,input().split()) GCD=gcd(x,y) if x==0: print(y*D) continue if y==0: print(x*D) continue x2=x//GCD y2=y//GCD # (z,w) = (x,y) + k(-y2,x2) # 0<=x-ky2<=D # 0<=y+kx2<=D # k<=x/y2,k<=(D-y)/x2,k>=(x-D)/y2,k>=-y/x2 MAX=min(x//y2,(D-y)//x2) MIN=max((x-D+y2-1)//y2,(-y+x2-1)//x2) if MIN<=MAX: A1=abs(x*(y+MIN*x2)-y*(x-MIN*y2)) A2=abs(x*(y+MAX*x2)-y*(x-MAX*y2)) print(max(A1,A2)) else: print(0)