#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); }; const int64_t z = bins(1, INT32_MAX, f), w = bins(-1, INT32_MIN, f); const int64_t nx = x - y * z, ny = y + x * z; const int64_t mx = x - y * w, my = y + x * w; dump(z, nx, ny); dump(w, mx, my); if(scope(0, nx, d) && scope(0, ny, d)) { return std::round(a * std::hypotl(nx - x, ny - y)); } else if(scope(0, mx, d) && scope(0, my, d)) { return std::round(a * std::hypotl(mx - x, my - y)); } return 0; } } 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'; } }