#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
struct node{
	ll k,v;
};
bool cmp(node a1,node a2)
{
	return a1.k<a2.k;
}
ll n;
int main(void)
{
	ll t;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld",&n);
		ll ans=0;
		vector<node> l,r;
		for(ll i=0;i<n;i++)
		{
			ll k,l1,r1;
			scanf("%lld%lld%lld",&k,&l1,&r1);
			if(l1==r1||k==n) ans+=l1;
			else if(l1>r1)
			{
				ans+=r1;
				l.push_back((node){k,l1-r1});
			}
			else
			{
				ans+=l1;
				r.push_back((node){n-k,r1-l1});
			}
		}
		sort(l.begin(),l.end(),cmp);
		sort(r.begin(),r.end(),cmp);
		priority_queue<ll , vector<ll>, greater<ll> > pq;
		for(ll i=0;i<l.size();i++)
		{
			if(l[i].k>pq.size())
			{
				pq.push(l[i].v);
			}
			else
			{
				if(pq.top()<l[i].v)
				{
					pq.pop();
					pq.push(l[i].v);
				}
			}
		}
		while(pq.size()) ans+=pq.top(),pq.pop();
		for(ll i=0;i<r.size();i++)
		{
			if(r[i].k>pq.size())
			{
				pq.push(r[i].v);
			}
			else
			{
				if(pq.top()<r[i].v)
				{
					pq.pop();
					pq.push(r[i].v);
				}
			}
		}
		while(pq.size()) ans+=pq.top(),pq.pop();
		printf("%lld\n",ans);
	}
}