#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, a[202020], b[202020], k[202020];
bool used[202020], used2[202020];
P p[202020];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> k[i] >> a[i] >> b[i];
		k[i]--;
		p[i] = P(abs(b[i]-a[i]), i);
	}
	sort(p, p+n, greater<P>());
	
	fill(used,used+n,0);
	fill(used2,used2+n,0);
	int l = 0, r = n-1;
	i64 cnt = 0;
	for(int i = 0; i < n; i++){
		int j = p[i].second;
		if(a[j] > b[j]){
			if(l > k[j]) cnt += b[j];
			else{
				cnt += a[j];
				int pos = k[j];
				while(used[pos]) pos--;
				used[pos] = 1;
				while(used[l]) l++;
			}
		}
		else{
			if(r <= k[j]) cnt += a[j];
			else{
				cnt += b[j];
				int pos = k[j]+1;
				while(used2[pos]) pos++;
				used2[pos] = 1;
				while(used2[r]) r--;
			}
		}
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}