#include using namespace std; using i64 = long long; i64 solve() { int d, x, y; cin >> d >> x >> y; if(x == 0 || y == 0) return max(x, y) * (i64)d; int g = gcd(x, y), dx = x / g, dy = y / g; int len = max(min((d - x) / dy, y / dx), min((d - y) / dx, x / dy)); return ((i64)dx * dx + (i64)dy * dy) * g * len; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T --) { cout << solve() << "\n"; } }