#include <bits/stdc++.h>
using namespace std;
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;
}
void solve() {
  long long int ans = 0;
  priority_queue<pair<long long int, long long int>> q;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      qq;
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int k, l, r;
    cin >> k >> l >> r;
    if (l - r > 0) {
      q.push({k, l - r});
      ans += r;
    } else {
      qq.push({k, r - l});
      ans += l;
    }
  }
  long long int now = 0;
  multiset<long long int> s;
  long long int cnt = 0;
  for (long long int i = n; i >= 1; i--) {
    while (q.size() && q.top().first >= i) {
      s.insert(q.top().second);
      q.pop();
    }
    if (s.size() == 0) continue;
    ans += (*s.begin());
    s.erase(s.begin());
  }
  s.clear();
  for (long long int i = 1; i <= n; i++) {
    while (qq.size() && qq.top().first < i) {
      s.insert(qq.top().second);
      qq.pop();
    }
    if (s.size() == 0) continue;
    ans += (*s.begin());
    s.erase(s.begin());
  }
  cout << ans << endl;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
