#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

struct tri
{
	int k, l, r;
};

bool cmp(tri a, tri b)
{
	return abs(a.l - a.r) > abs(b.l - b.r);
}

int32_t main()
{
	FIO;
	w(t)
	{
		int n; cin >> n;
		mk(arr, n, tri);

		int ans = 0;
		set<int> left;
		for (int i = 0; i < n; ++i)
		{
			cin >> arr[i].k >> arr[i].l >> arr[i].r;
			arr[i].k--;
			left.insert(i);
		}

		sort(arr, arr + n, cmp);

		for (int i = 0; i < n; ++i)
		{

			auto it = left.upper_bound(arr[i].k);

			if (arr[i].l > arr[i].r)
			{
				if (it != left.begin())
				{
					ans += arr[i].l;
					it--;
					left.erase(it);
				}
				else
					ans += arr[i].r;
			}

			else
			{
				if (it != left.end())
				{
					ans += arr[i].r;
					left.erase(it);
				}
				else
					ans += arr[i].l;
			}
		}

		cout << ans << '\n';
	}
	return 0;
}