using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var c = NList; ans[u] = Tri(c[0], c[1], c[2]); } WriteLine(string.Join("\n", ans)); } static long Tri(long d, long x, long y) { if (x == 0) { return y * d; } if (y == 0) { return x * d; } var gcd = GCD(x, y); var dx = x / gcd; var dy = y / gcd; var maxa = Math.Min(x / dy, (d - y) / dx); var mina = Math.Max((x - d) / dy, - y / dx); return (x * x + y * y) / gcd * Math.Max(Math.Abs(maxa), Math.Abs(mina)); } static long GCD(long a, long b) { if (a < b) return GCD(b, a); if (a % b == 0) return b; return GCD(b, a % b); } }