from math import gcd
T=int(input())
for i in range(T):
	D,x,y=map(int,input().split())
	if x==0 or y==0:
		print(max(x,y)*D)
		continue
	a,b=x//gcd(x,y),y//gcd(x,y)
	s=min(x//b,(D-y)//a)
	t=min(y//a,(D-x)//b)
	use=max(s,t)
	px=x-b*use
	py=y+a*use
	print(abs(px*y-py*x))