期望dp
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
const double eps = 1e-7;
int t;
double c, m, p, v;
double dp(double c, double m, double p) {
double res = 0;
if (c > eps) {
double x = min(c, v);
if (m > eps && p > eps)res += c * (dp(c - x, m + x / 2, p + x / 2) + 1);
else if (m > eps)res += c * (dp(c - x, m + x, p) + 1);
else res += c * (dp(c - x, m, p + x) + 1);
}
if (m > eps) {
double x = min(m, v);
if (c > eps && p > eps)res += m * (dp(c + x / 2, m - x, p + x / 2) + 1);
else if (c > eps)res += m * (dp(c + x, m - x, p) + 1);
else res += m * (dp(c, m - x, p + x) + 1);
}
return res;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%lf%lf%lf%lf", &c, &m, &p, &v);
printf("%.10lf\n", 1.0 + dp(c, m, p));
}
return 0;
}