#include void solve() { long long D, x, y; std::cin >> D >> x >> y; long long L = std::gcd(x, y); std::pair v = {-y / L, x / L}; long long ans = 0; long long ac = 0, wa = 1 << 30; while (wa - ac > 1) { long long wj = (ac + wa) / 2; long long a = x + v.first * wj, b = y + v.second * wj; if (0 <= a && a <= D && 0 <= b && b <= D) { ac = wj; } else { wa = wj; } } long long a = x + v.first * ac, b = y + v.second * ac; ans = std::abs(x * b - y * a); ac = 0, wa = 1 << 30; while (wa - ac > 1) { long long wj = (ac + wa) / 2; long long c = x - v.first * wj, d = y - v.second * wj; if (0 <= c && c <= D && 0 <= d && d <= D) { ac = wj; } else { wa = wj; } } long long c = x - v.first * ac, d = y - v.second * ac; ans = std::max(ans, std::abs(x * d - y * c)); std::cout << ans << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int testcases = 1; std::cin >> testcases; for (;testcases--;) { solve(); } return 0; }