import sys import math def gcd(a, b): c = a d = b if c == 0 or d == 0: return max(a, b) if c < d: e = c c = d d = e while c % d != 0: c //= d e = c c = d d = e return d t = int(input()) for i in range(t): d, x, y = map(int, input().split()) if x == 0 or y == 0: print(max(x, y) * d) continue e = y f = x g = gcd(e, f) e //= g f //= g c = min((d - y) // f, x // e) e = min(y // f, (d - x) // e) print(max(0, max(c, e) * (x * x + y * y)))