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(-y,x) # 0<=x-ky<=D # 0<=y+kx<=D # k<=x/y,k<=(D-y)/x,k>=(x-D)/y,k>=-y/x MAX=min(x2//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)