#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

int main(){
  int t;
  cin >> t;
  for(int i=0; i<t; ++i){
    int n;
    cin >> n;
    priority_queue<P> que1;
    priority_queue<P> que2;
    ll ans = 0;
    for(int i=0; i<n; ++i){
      int k, l, r;
      cin >> k >> l >> r;
      if(l == r) ans += l;
      else if(l > r){
        que1.push(make_pair(k,l-r));
        ans += r;
      }else{
        que2.push(make_pair(n-k,r-l));
        ans += l;
      }
    }
    //cout << "minans" << ans << endl;
    int n1 = que1.size();
    priority_queue<int> que3;
    for(int i=n1; i>0; --i){
      while(!que1.empty() && que1.top().first >= i){
        que3.push(que1.top().second);
        que1.pop();
      }
      if(!que3.empty()){
        ans += que3.top();
        que3.pop();
      }
    }
    int n2 = que2.size();
    //cout << n1 << " " << n2 << endl;
    priority_queue<int> que4;
    for(int i=n2; i>0; --i){
      while(!que2.empty() && que2.top().first >= i){
        que4.push(que2.top().second);
        que2.pop();
      }
      if(!que4.empty()){
        ans += que4.top();
        que4.pop();
      }
    }
    cout << ans << endl;
  }
}