#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int T,n,cnt1,cnt2,cnt3,ans,maxx;
int a[N][5];
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	freopen("club.in","r",stdin);
	freopen("club.out","w",stdout);
	cin>>T;
	while(T--){
		priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q1,q2,q3; 
		cnt1=cnt2=cnt3=ans=0;
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i][1]>>a[i][2]>>a[i][3];
		for(int i=1;i<=n;i++){
			maxx=max(max(a[i][1],a[i][2]),a[i][3]);
			if(maxx==a[i][1]){
				if(cnt1<(n>>1)){
					q1.push(make_pair(maxx,i));
					cnt1++;
					ans+=maxx;
				}
				else{
					int x=q1.top().first,y=q1.top().second;
					if(ans-x+maxx+max(a[y][2],a[y][3])>ans+max(a[i][2],a[i][3])){
						q1.pop();q1.push(make_pair(maxx,i));
						ans-=x;ans+=maxx;
						if(a[y][2]>a[y][3]){
							q2.push(make_pair(a[y][2],y));
							cnt2++;
							ans+=a[y][2];
						}
						else{
							q3.push(make_pair(a[y][3],y));
							cnt3++;
							ans+=a[y][3];
						}
					}
					else if(ans-x+maxx+max(a[y][2],a[y][3])==ans+max(a[i][2],a[i][3])){
						if(max(a[y][2],a[y][3])>max(a[i][2],a[i][3])){
							if(a[i][2]>a[i][3]){
								q2.push(make_pair(a[i][2],i));
								cnt2++;
								ans+=a[i][2];
							}
							else{
								q3.push(make_pair(a[i][3],i));
								cnt3++;
								ans+=a[i][3];
							}
						}
						else{
							q1.pop();q1.push(make_pair(maxx,i));
							ans-=x;ans+=maxx;
							if(a[y][2]>a[y][3]){
								q2.push(make_pair(a[y][2],y));
								cnt2++;
								ans+=a[y][2];
							}
							else{
								q3.push(make_pair(a[y][3],y));
								cnt3++;
								ans+=a[y][3];
							}
						}
					}
					else{
						if(a[i][2]>a[i][3]){
							q2.push(make_pair(a[i][2],i));
							cnt2++;
							ans+=a[i][2];
						}
						else{
							q3.push(make_pair(a[i][3],i));
							cnt3++;
							ans+=a[i][3];
						}
					}
				}
			}
			else if(maxx==a[i][2]){
				if(cnt2<(n>>1)){
					q2.push(make_pair(maxx,i));
					cnt2++;
					ans+=maxx;
				}
				else{
					int x=q2.top().first,y=q2.top().second;
					if(ans-x+maxx+max(a[y][1],a[y][3])>ans+max(a[i][1],a[i][3])){
						q2.pop();q2.push(make_pair(maxx,i));
						ans-=x;ans+=maxx;
						if(a[y][1]>a[y][3]){
							q1.push(make_pair(a[y][1],y));
							cnt1++;
							ans+=a[y][1];
						}
						else{
							q3.push(make_pair(a[y][3],y));
							cnt3++;
							ans+=a[y][3];
						}
					}
					else if(ans-x+maxx+max(a[y][1],a[y][3])==ans+max(a[i][1],a[i][3])){
						if(max(a[y][1],a[y][3])>max(a[i][1],a[i][3])){
							if(a[i][1]>a[i][3]){
								q1.push(make_pair(a[i][1],i));
								cnt1++;
								ans+=a[i][1];
							}
							else{
								q3.push(make_pair(a[i][3],i));
								cnt3++;
								ans+=a[i][3];
							}
						}
						else{
							q2.pop();q2.push(make_pair(maxx,i));
							ans-=x;ans+=maxx;
							if(a[y][1]>a[y][3]){
								q1.push(make_pair(a[y][1],y));
								cnt1++;
								ans+=a[y][1];
							}
							else{
								q3.push(make_pair(a[y][3],y));
								cnt3++;
								ans+=a[y][3];
							}
						}
					}
					else{
						if(a[i][1]>a[i][3]){
							q1.push(make_pair(a[i][1],i));
							cnt1++;
							ans+=a[i][1];
						}
						else{
							q3.push(make_pair(a[i][3],i));
							cnt3++;
							ans+=a[i][3];
						}
					}
				}
			}
			
			else{
				if(cnt3<(n>>1)){
					q3.push(make_pair(maxx,i));
					cnt3++;
					ans+=maxx;
				}
				else{
					int x=q3.top().first,y=q3.top().second;
					if(ans-x+maxx+max(a[y][1],a[y][2])>ans+max(a[i][1],a[i][2])){
						q3.pop();q3.push(make_pair(maxx,i));
						ans-=x;ans+=maxx;
						if(a[y][1]>a[y][2]){
							q1.push(make_pair(a[y][1],y));
							cnt1++;
							ans+=a[y][1];
						}
						else{
							q2.push(make_pair(a[y][2],y));
							cnt2++;
							ans+=a[y][2];
						}
					}
					else if(ans-x+maxx+max(a[y][1],a[y][2])==ans+max(a[i][1],a[i][2])){
						if(max(a[y][1],a[y][2])>max(a[i][1],a[i][2])){
							if(a[i][1]>a[i][2]){
								q1.push(make_pair(a[i][1],i));
								cnt1++;
								ans+=a[i][1];
							}
							else{
								q2.push(make_pair(a[i][2],i));
								cnt2++;
								ans+=a[i][2];
							}
						}
						else{
							q3.pop();q3.push(make_pair(maxx,i));
							ans-=x;ans+=maxx;
							if(a[y][1]>a[y][2]){
								q1.push(make_pair(a[y][1],y));
								cnt1++;
								ans+=a[y][1];
							}
							else{
								q2.push(make_pair(a[y][2],y));
								cnt2++;
								ans+=a[y][2];
							}
						}
					}
					else{
						if(a[i][1]>a[i][2]){
							q1.push(make_pair(a[i][1],i));
							cnt1++;
							ans+=a[i][1];
						}
						else{
							q2.push(make_pair(a[i][2],i));
							cnt2++;
							ans+=a[i][2];
						}
					}
				}
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
