import math
def solve():
    d,x,y = map(int,input().split())
    if x == 0 or y == 0:
        print(max(x,y)*d)
        return
    g = math.gcd(x,y)
    ans = 0
    
    xx = x//g
    yy = y//g
    z = min(x//yy,(d-y)//xx)
  
    ans = max(ans,abs(x*(y+z*xx)-y*(x-z*yy)))


    z = min((d-x)//yy,y//xx)
    ans = max(ans,abs(x*(y-z*xx)-y*(x+z*yy)))
    print(ans)
for i in range(int(input())):
    solve()