from math import gcd def solve(): D,x,y = map(int,input().split()) if x == 0: print(D * y) return if y == 0: print(D * x) return if x < y: x,y = y,x t = gcd(x,y) xd = y // t yd = x // t a = (D - y) // yd a = min(a, x // xd) return (x ** 2 + y ** 2) * a // t for _ in range(int(input())): print(solve())