// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include #include #include using namespace std; using namespace __gnu_pbds; // #include // using mint = atcoder::modint998244353; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) // const ll dy[] = {-1, -1, -1, 0, 0, 1, 1, 1}; // const ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const ll dy[] = {-1, 0, 0, 1}; const ll dx[] = {0, -1, 1, 0}; template bool isrange(T target, T1 low, T2 high) { return low <= target && target < high; } template T min(const T &t, const U &u) { return t < u ? t : u; } template T max(const T &t, const U &u) { return t < u ? u : t; } template bool chmin(T &t, const U &u) { if (t > u) { t = u; return true; } return false; } template bool chmax(T &t, const U &u) { if (t < u) { t = u; return true; } return false; } template using hash_map = gp_hash_table; template using hash_set = gp_hash_table; // #include "titan_cpplib/others/io.cpp" // #include "titan_cpplib/others/print.cpp" const double pi = 3.141592653589793238462643383279; void solve() { double xa, ya, za, ra; cin >> xa >> ya >> za >> ra; double xb, yb, zb, rb; cin >> xb >> yb >> zb >> rb; if (ra > rb) { swap(xa, xb); swap(ya, yb); swap(za, zb); swap(ra, rb); } double d2 = (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) + (za-zb)*(za-zb); if (d2 > (ra+rb)*(ra+rb)) { cout << 0 << "\n"; return; } if (d2 <= (ra-rb)*(ra-rb)) { cout << 4*pi*ra*ra*ra / 3 << "\n"; return; } const double d = sqrt(d2); cout << (pi/(12*d)) * (ra+rb-d)*(ra+rb-d) * (d2 + (ra+rb)*d*2 - 3*(ra-rb)*(ra-rb)) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); int t = 1; cin >> t; for (int i = 0; i < t; ++i) { solve(); } return 0; }