from math import gcd

def solve():
    D,x,y = map(int,input().split())
    if x == 0:
        return D * y
    if y == 0:
        return D * x
    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())