#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; constexpr auto pi = numbers::pi_v; cout << fixed << setprecision(16); while (tt--) { long double xa, ya, za, ra, xb, yb, zb, rb; cin >> xa >> ya >> za >> ra >> xb >> yb >> zb >> rb; xa -= xb; ya -= yb; za -= zb; auto d2 = xa * xa + ya * ya + za * za; if (d2 >= (ra + rb) * (ra + rb)) { cout << 0 << '\n'; continue; } if (d2 <= (ra - rb) * (ra - rb)) { auto r = min(ra, rb); cout << 4 * pi * r * r * r / 3 << '\n'; continue; } auto d = sqrtl(d2); auto s = sqrtl((ra + rb + d) * ((d2-ra*ra)/(d+ra) + rb) * ((d2-rb*rb)/(d+rb) + ra) * (ra + (rb*rb-d2)/(rb+d))) / 4; auto h = 2 * s / d; auto ta = sqrtl(ra * ra - h * h); auto tb = sqrtl(rb * rb - h * h); auto ans = 0.0L; ans += h * h * h * h / ((ra + ta) * (ra + ta)) * (2 * ra + ta); ans += h * h * h * h / ((rb + tb) * (rb + tb)) * (2 * rb + tb); ans = ans * pi / 3; cout << ans << '\n'; } }