import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from math import gcd for _ in range(ni()): d, x, y = na() g = gcd(x, y) if y > x: x, y = y, x s = (d - y) // (x // g) if y: s = min(s, x // (y // g)) X = x - s * y Y = y + s * x print((x * x + y * y) * s // g)