#pragma GCC optimize ("O3") #pragma GCC optimize ("fast-math") #pragma GCC target ("avx") #include using namespace std; const int N = 1 << 17; const double lte = -4 * log(10); double lg[N + 2]; double ex[20202]; double fastexp(double x) { return exp(x); //int a = floor(x * 1e3); //double b = x - a * 1e-3; //return ex[a + 10000] * (((b / 3 + 1) * b / 2 + 1) * b + 1); } // ref: https://en.wikipedia.org/wiki/Lambert_W_function, Numerical evaluation // Halley's method double lambert(double z, double init) { double w = init; for (int i = 0; i < 3; i++) { double ew = fastexp(w); double a = w * ew - z; double b = ew * (w + 1) - (w + 2) * (w * ew - z) / (2 * w + 2); w -= a / b; } return w; } namespace fastio { #define getchar getchar_unlocked #define putchar putchar_unlocked bool dot; int readInt() { int n, c; while ((c = getchar()) < '0') { assert(c != EOF); } n = c - '0'; while ((c = getchar()) >= '0') { n = n * 10 + c - '0'; } dot = c == '.'; return n; } void printDouble(double x) { int a = x; int b = (x - a) * 1e9; int d[15]; int i = 0; for (int j = 0; j < 9; j++) { d[i++] = b % 10 + '0'; b /= 10; } d[i++] = '.'; do { d[i++] = a % 10 + '0'; a /= 10; } while (a > 0); while (i > 0) { putchar(d[--i]); } putchar('\n'); } } double solve(int a, int b, int c, int d) { double lt = lg[c * 10000 + d]; if (b == 0) { return fastexp(lt / a); } if (a == 0) { return fastexp(fastexp(lt / b)); } double init = max(0.0, lt / b + lg[a] - lg[b]); return fastexp(lambert(fastexp(lt / b) * a / b, init) * b / a); } int main() { for (int i = 0; i <= 20000; i++) { ex[i] = exp((i - 10000) * 1e-3); } for (int i = 0; i < N / 2; i++) { lg[i] = log(i) + lte; } for (int i = N / 2; i < N + 2; i += 2) { double li = log(i); double lj = li + 1.0 / i; lg[i + 0] = li + lte; lg[i + 1] = lj + lte; } int m = fastio::readInt(); for (int i = 0; i < m; i++) { int a = fastio::readInt(); int b = fastio::readInt(); int c = fastio::readInt(); int d = fastio::dot ? fastio::readInt() : 0; fastio::printDouble(solve(a, b, c, d)); } }