from sys import stdin from random import randint from collections import deque, defaultdict as dd from copy import deepcopy input = stdin.readline MOD = 998244353 INF = 1 << 60 xor = randint(100, INF) def extended_gcd(a, b): if b == 0: return a, 1, 0 else: g, x, y = extended_gcd(b, a % b) return g, y, x - (a // b) * y def mod_inverse(a, m): _, x, _ = extended_gcd(a, m) return (x % m + m) % m def main(): t = int(input()) for _ in range(t): solve() def solve(): d, x, y = map(int, input().split()) a = x*x+y*y gcd = extended_gcd(x, y)[0] base = max(min(x//(y//gcd), (d-y)//(x//gcd)), min(y//(x//gcd), (d-x)//(y//gcd))) print(a*base//gcd) if __name__ == "__main__": main()