#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int T;
	cin>>T;
	
	for(int _=0;_<T;_++){
		int N;
		cin>>N;
		
		vector<long long> K(N),L(N),R(N);
		for(int i=0;i<N;i++)cin>>K[i]>>L[i]>>R[i];
		
		vector<pair<long long,long long>> l,r;
		long long ans = 0LL;
		for(int i=0;i<N;i++){
			if(L[i]>R[i]){
				ans += R[i];
				l.emplace_back(K[i]-1,L[i]-R[i]);
			}
			else{
				ans += L[i];
				r.emplace_back(N-K[i]-1,R[i]-L[i]);
			}
		}
		sort(l.begin(),l.end());
		sort(r.begin(),r.end());
		priority_queue<long long,vector<long long>,greater<long long>> Q;
		for(int i=0;i<l.size();i++){
			if(Q.size()<=l[i].first){
				ans += l[i].second;
				Q.push(l[i].second);
			}
			else{
				if(Q.size()==0)continue;
				if(Q.top()<l[i].second){
					ans -= Q.top();
					Q.pop();
					ans += l[i].second;
					Q.push(l[i].second);
				}
			}
		}
		
		while(Q.size()!=0)Q.pop();
		for(int i=0;i<r.size();i++){
			if((int)Q.size()<=r[i].first){
				ans += r[i].second;
				Q.push(r[i].second);
			}
			else{
				if(Q.size()==0)continue;
				if(Q.top()<r[i].second){
					ans -= Q.top();
					Q.pop();
					ans += r[i].second;
					Q.push(r[i].second);
				}
			}
		}
		
		cout<<ans<<endl;
		
		
	}
	
	return 0;
}
