import math def solve(): d,x,y = map(int,input().split()) 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))) 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))) print(ans) for i in range(int(input())): solve()