from math import gcd
T=int(input())
for _ in range(T):
    D,x,y=map(int,input().split())
    def in_map(x,y):
        return 0<=x<=D and 0<=y<=D
        
    g=gcd(x,y)
    gx=x//g
    gy=y//g

    ans=0
    ok=0
    ng=int(1e18)
    while ng-ok>1:
        m=(ok+ng)//2
        
        nx=x-gy*m
        ny=y+gx*m
        if in_map(nx,ny):ok=m
        else:ng=m

    ans=max(ans,ok*g*(gx**2+gy**2))

    ok=0
    ng=int(1e18)
    while ng-ok>1:
        m=(ok+ng)//2
        
        nx=x+gy*m
        ny=y-gx*m
        if in_map(nx,ny):ok=m
        else:ng=m
    ans=max(ans,ok*g*(gx**2+gy**2))
    print(ans)