T=int(input()) from math import gcd for _ in range(T): D,x,y=map(int,input().split()) g=gcd(x,y) dx,dy=x//g,y//g s=0 ok=0 ng=10**10 while ng-ok>1: m=(ok+ng)//2 if 0<=x-dy*m<=D and 0<=y+dx*m<=D: ok=m else: ng=m s=max(s,((x//g)**2+(y//g)**2)*g*ok) ok=0 ng=10**10 while ng-ok>1: m=(ok+ng)//2 if 0<=x+dy*m<=D and 0<=y-dx*m<=D: ok=m else: ng=m s=max(s,((x//g)**2+(y//g)**2)*g*ok) print(s)