#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
struct node{int v,k;}a[N],b[N];
int n,na,nb;
ll ans;
bool operator<(node a,node b){return a.k<b.k;}	
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		ans=0,na=0,nb=0;
		for(int i=1;i<=n;i++)
		{
			int k,l,r;scanf("%d%d%d",&k,&l,&r);
			if(l>r)ans+=r,a[++na]=(node){l-r,k};
			else ans+=l,b[++nb]=(node){r-l,n-k};
		}
		sort(a+1,a+na+1),sort(b+1,b+nb+1);
		for(int i=1;i<=na;i++)
		if(a[i].k)
		{
			if(q.size()<a[i].k)q.push(a[i].v);
			else if(q.size()==a[i].k&&a[i].v>q.top())q.pop(),q.push(a[i].v);
		}
		while(!q.empty())ans+=q.top(),q.pop();
		for(int i=1;i<=nb;i++)
		if(b[i].k)
		{
			if(q.size()<b[i].k)q.push(b[i].v);
			else if(q.size()==b[i].k&&b[i].v>q.top())q.pop(),q.push(b[i].v);
		}
		while(!q.empty())ans+=q.top(),q.pop();
		printf("%lld\n",ans);
	}
}