#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #ifdef local #include "debug_print.hpp" #else #define dump(...) void(0); #endif #include #include #include #include #include namespace man { constexpr inline bool scope(const int l, const int x, const int r) noexcept { return l <= x && x <= r; } constexpr inline int64_t bins(int64_t ok, int64_t ng, const auto &f) noexcept { while(std::abs(ok - ng) > 1) { const auto x = (ok + ng) / 2; if(f(x)) { ok = x; } else { ng = x; } } return ok; } inline int64_t solve() noexcept { int d; int64_t x, y; std::cin >> d >> x >> y; const auto a = std::hypotl(x, y); const auto f = [&](const int64_t z) -> bool { const int64_t nx = x - y * z, ny = y + x * z; return (scope(0, nx, d) && scope(0, ny, d)); }; if(!f(1) && !f(-1)) { return 0; } const auto z = bins(INT32_MIN, INT32_MAX, f); const int64_t nx = x - y * z, ny = y + x * z; dump(z, nx, ny); dump(a, std::hypotl(std::abs(nx - x), std::abs(ny - y))); return std::round(a * std::hypotl(std::abs(nx - x), std::abs(ny - y))); } } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); int t; std::cin >> t; std::cout << std::fixed << std::setprecision(12); for([[maybe_unused]] const auto _: std::views::iota(0, t)) { std::cout << man::solve() << '\n'; } }