from math import gcd for _ in range(int(input())): D, x, y = map(int, input().split()) if x == 0: print(y * D) elif y == 0: print(x * D) else: g = gcd(x, y) xg, yg = x // g, y // g ans = 0 a1 = min((D - y) // xg, x // yg) ans = max(ans, (x * x + y * y) // g * a1) a2 = min((D - x) // yg, y // xg) ans = max(ans, (x * x + y * y) // g * a2) print(ans)