import math T=int(input()) for _ in range(T): D,x,y=map(int,input().split()) if x==0 or y==0: l=x if y!=0: l=y print(l*l*(D//l)) continue gcd=math.gcd(x,y) x2,y2=x//math.gcd(x,y),y//math.gcd(x,y) s1=min((D-x)//y2,y//x2) s2=min((D-y)//x2,x//y2) base=x2**2+y2**2 #print(base,s1,s2) print(base*gcd*max(s1,s2,0))