#include <iostream>
#include <numeric>
#include <utility>

using namespace std;
using ll = long long;

int main () {
    int T; cin >> T;
    for (int z = 0; z < T; z++) {
        int D, x, y; cin >> D >> x >> y;
        int d = gcd(x, y);

        auto v = make_pair(-y / d, x / d);
        auto ch = [&] (int mul) {
            ll nx = 1LL * mul * v.first + x;
            ll ny = 1LL * mul * v.second + y;

            if (nx < 0 || D < nx) return false;
            if (ny < 0 || D < ny) return false;
            return true;
        };

        auto bs = [&] () {
            int ok = 0, ng = 1000000000 + 10;
            while (1 < abs(ok - ng)) {
                int m = (ok + ng) / 2;
                if (ch(m)) {
                    ok = m;
                }
                else {
                    ng = m;
                }
            }
            return ok;
        };

        int p = bs();
        v.first = -v.first;
        v.second = -v.second;
        int q = bs();

        int r = max(p, q);

        ll area = (1LL * x * x + 1LL * y * y) / d * r;
        cout << area << "\n";
    }
}