#include #include #include #include #include int main() { using namespace std; using bigint = boost::multiprecision::cpp_int; ios::sync_with_stdio(false); cin.tie(nullptr); unsigned T; cin >> T; for ([[maybe_unused]] const auto _ : views::repeat(monostate{}, T)) [] { unsigned N; double _x; cin >> N >> _x; int X = round(_x * 100000), Y = 100000; int g{gcd(X, Y)}; X /= g; Y /= g; bigint real = 1, imag = 0; for (unsigned i{8}; i--; ) { tie(real, imag) = pair{(real + imag) * (real - imag), real * imag * 2}; if (N + 1 >> i & 1) tie(real, imag) = pair{-real * X - imag * Y, real * Y - imag * X}; } long abs_sq = static_cast(X) * X + static_cast(Y) * Y; bigint ans; if (N % 2 == 0) { ans = max(imag, -imag) * g / boost::multiprecision::pow(bigint{abs_sq}, N / 2); } else if (int abs_round = round(sqrt(abs_sq)); abs_sq == static_cast(abs_round) * abs_round) { ans = max(imag, -imag) * g / boost::multiprecision::pow(bigint{abs_round}, N); } else { bigint mag_sq = imag * g * (imag * g) / boost::multiprecision::pow(bigint{abs_sq}, N); ans = static_cast(sqrt(static_cast(mag_sq)) + 1); do ans = (ans + mag_sq / ans) / 2; while (mag_sq / ans / ans == 0); } cout << (imag < 0 ? "-" : "") << ans / 100000 << "." << setw(5) << setfill('0') << ans % 100000 << '\n'; }(); return 0; }