神秘
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using std::printf;
using std::scanf;
using std::vector;
using std::pair;
int main()
{
int t, n;
long long ans;
vector<pair<pair<int, int>, int>> a;
vector<std::priority_queue<int, vector<int>, std::greater<int>>> pq;
scanf("%d", &t);
while (t-- > 0)
{
ans = 0;
scanf("%d", &n);
//a.clear();
//pq.clear();
a.resize(n);
pq.resize(3, std::priority_queue<int, vector<int>, std::greater<int>>());
for (int i = 0; i < n; i++)
{
int a1, a2, a3;
scanf("%d %d %d", &a1, &a2, &a3);
if (a1 > a2)
if (a1 > a3)
{
a[i].first.first = 0;
a[i].first.second = a1;
a[i].second = a2 > a3 ? a2 : a3;
}
else
{
a[i].first.first = 2;
a[i].first.second = a3;
a[i].second = a1;
}
else
if (a2 > a3)
{
a[i].first.first = 1;
a[i].first.second = a2;
a[i].second = a1 > a3 ? a1 : a3;
}
else
{
a[i].first.first = 2;
a[i].first.second = a3;
a[i].second = a2;
}
ans += a[i].first.second;
pq[a[i].first.first].push(a[i].first.second - a[i].second);
}
for (int i = 0; i < 3; i++)
for (int j = n >> 1; j < pq[i].size(); j++)
{
ans -= pq[i].top();
pq[i].pop();
}
printf("%lld\n", ans);
}
return 0;
}