#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
// #define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int solve(){
	int n;
	cin>>n;
	int ans = 0;
	vi v[n],g[n];
	for (int i = 0; i < n; ++i)
	{
		int k,l,r;
		cin>>k>>l>>r;
		k--;
		if(l >= r){
			ans += r;
			v[k].emplace_back(l-r);
		}
		else{
			ans += l;
			if(n-k-2 >= 0) g[n-k-2].emplace_back(r-l);
		}
	}
	multiset<int>s;
	for (int i = 0; i < n; ++i)
	{
		for(const auto it:v[i]){
			s.insert(it);
		}
		while(s.size() > (i+1)){
			s.erase(s.begin());
		}
	}
	for(auto it:s) ans += it;
	// show(ans);
	s.clear();
	for (int i = 0; i < n; ++i)
	{
		for(const auto it:g[i]){
			s.insert(it);
		}
		while(s.size() > (i+1)){
			s.erase(s.begin());
		}
	}
	for(auto it:s) ans += it;
	return ans;
}

int32_t main(){
    fast_io;
    int t;
    cin>>t;
    while(t--){
    	show(solve());
    }
    return 0;
}