#include #include #include #include using namespace std; #define getchar getchar_unlocked #define putchar putchar_unlocked bool dot; int in() { int n, c; while ((c = getchar()) < '0') { assert(c != EOF); } n = c - '0'; while ((c = getchar()) >= '0') { n = n * 10 + c - '0'; } if (c == '.') { dot = true; } return n; } void out(double x) { static char buf[20]; sprintf(buf, "%.9f", x); for (int i = 0; buf[i] != '\0'; i++) { putchar(buf[i]); } putchar('\n'); } const int H = 17; const int N = 1 << H; double lg[N + 1]; bool prime[N + 1]; int main() { const double L = 0; const double R = log(10); const double LL = -1e100; const double RR = log(R); const double dx = R / (1 << H); const double logDX = log(R) - H * log(2); const double log00001 = -4 * log(10); lg[0] = log(0); for (int i = 2; i <= N; i++) { if (!prime[i]) { double g = log(i); for (long long j = i; j < N; j *= i) { for (long long k = j; k < N; k += j) { prime[k] = true; lg[k] += g; } } } } for (int i = 0; i <= N; i++) { lg[i] += logDX; } int m = in(); while (m--) { int a = in(); int b = in(); int c = in(); int d = dot ? in() : 0; double t = c + 1e-4 * d; double logT = lg[c * 10000 + d] - logDX + log00001; if (b == 0) { out(exp(logT / a)); continue; } if (a == 0) { out(exp(exp(logT / b))); continue; } int l = 0; int r = N; while (r - l > 1) { int mid = (l + r) / 2; (a * mid * dx + b * lg[mid] >= logT ? r : l) = mid; } double s = (lg[r] - lg[l]) / dx; double ans = (logT + s * b * l * dx - lg[l] * b) / (s * b + a); out(exp(ans)); } }