#include<bits/stdc++.h>
using namespace std;
using db = __int128;
using T = db;
struct P {
T x, y, z;
explicit P(T x = 0, T y = 0, T z = 0) : x(x), y(y), z(z) {}
T dot(P p) { return x * p.x + y * p.y + z * p.z; }
P cross(P p) { return P(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); }
P operator-(P p) { return P(x - p.x, y - p.y, z - p.z); }
db length() { return sqrt(x * x + y * y + z * z); }
// friend ostream& operator<<(ostream& os, P p) { return os << "(" << p.x << ", " << p.y << ", " << p.z << ")"; }
};
const int L = 1e5;
vector<tuple<int, int, int>> hull(vector<P> p, T eps = 1e-9) {
mt19937 mt(random_device{}());
int d = mt() % L;
for (auto& [x, y, z] : p) {
x += d;
y += d;
z += d;
}
vector<tuple<int, int, int>> res;
if(p.size() < 3)
return res;
res.emplace_back(0, 1, 2);
res.emplace_back(0, 2, 1);
for (int i = 3; i < p.size(); i += 1) {
vector<tuple<int, int, int>> nxt;
set<pair<int, int>> edge;
for (auto [a, b, c] : res) {
T prod = (p[b] - p[a]).cross(p[c] - p[a]).dot(p[i] - p[a]);
if (prod > 0) {
edge.emplace(a, b);
edge.emplace(b, c);
edge.emplace(c, a);
} else
nxt.emplace_back(a, b, c);
}
for (auto [x, y] : edge) {
if (edge.find({y, x})!=edge.end()) continue;
nxt.emplace_back(x, y, i);
}
res.swap(nxt);
}
return res;
}
db volume(vector<P> p, vector<tuple<int, int, int>> f) {
db res = 0;
for (auto [a, b, c] : f) res += p[a].cross(p[b]).dot(p[c]);
return res;
}
db area(vector<P> p, vector<tuple<int, int, int>> f) {
db res = 0;
for (auto [a, b, c] : f) res += (p[b] - p[a]).cross(p[c] - p[b]).length();
return res / 2;
}
int main() {
int T;
cin >> T;
while(T--) {
int n;
cin >> n;
vector<P> v(n);
for(auto &[x, y, z] : v) {
long long a, b, c;
cin >> a >> b >> c;
x = a, y = b, z = c;
// cin >> x >> y >> z;
}
db ans = 0;
while(v.size() > 3) {
auto h = hull(v);
ans += volume(v, h);
vector<int> use(v.size());
for(auto [x, y, z] : h)
use[x] = use[y] = use[z] = 1;
vector<P> nv;
for(int i = 0; i < v.size(); i += 1)
if(!use[i])
nv.push_back(v[i]);
v.swap(nv);
}
cout << (long long)(ans) << "\n";
}
}