import math J=lambda:map(int,input().split()) T,*_=J() for t in range(T):D,x,y=J();g=math.gcd(x,y);z,w=y//g,x//g;print((w*x+z*y)*max(0if xD else min(x//z if z else D,(D-y)//w if w else D),0if x+z>D or y