from math import gcd def solve(): d, x, y = map(int, input().split()) if x == 0 or y == 0: print(d * (x + y)) return g = gcd(x, y) dx = x // g dy = y // g mi1 = min(x // dy, (d - y) // dx) mi2 = min(y // dx, (d - x) // dy) mi = max(mi1, mi2) x2 = x - mi * dy y2 = y + mi * dx ans = x * y2 - x2 * y print(ans) for _ in range(int(input())): solve()