#include <bits/stdc++.h>
using namespace std;
template <class... A>
void prints() {
  cout << "\n";
}
template <class... A>
void prints_rest() {
  cout << "\n";
}
template <class T, class... A>
void prints_rest(const T &first, const A &...rest) {
  cout << " " << first;
  prints_rest(rest...);
}
template <class T, class... A>
void prints(const T &first, const A &...rest) {
  cout << first;
  prints_rest(rest...);
}
template <class T, class... A>
void printd(const T &first, const A &...rest) {
  cout << fixed << setprecision(15) << first;
  prints_rest(rest...);
}
namespace {
void printElems(const int *begin, const int *end) {
  for (const int *p = begin; p != end; ++p) {
    cout << *p << ' ';
  }
  cout << endl;
}
}  // namespace
const long long llinf = numeric_limits<long long>::max();
const long long _llinf = numeric_limits<long long>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const long long BIG = 1LL << 60;
priority_queue<int> neg[200005];
priority_queue<int> pos[200005];
int main() {
  int t;
  cin >> t;
  vector<long long> ans;
  for (int _ = 0; _ < t; _++) {
    int n;
    cin >> n;
    long long anstmp = 0;
    for (int i = 1; i < n + 1; i++) {
      while (!pos[i].empty()) pos[i].pop();
      while (!neg[i].empty()) neg[i].pop();
    }
    for (int i = 1; i < n + 1; i++) {
      long long k, l, r;
      cin >> k >> l >> r;
      anstmp += min(l, r);
      if (l > r) {
        pos[k].push(l - r);
      } else if (l < r) {
        neg[n - k].push(r - l);
      }
    }
    int pcnt = 0;
    int ncnt = 0;
    for (int i = 1; i < n + 1; i++) {
      while (!pos[i].empty() && pcnt < i) {
        anstmp += pos[i].top();
        pos[i].pop();
        pcnt++;
      }
      while (!neg[i].empty() && ncnt < i) {
        anstmp += neg[i].top();
        neg[i].pop();
        ncnt++;
      }
    }
    ans.push_back(anstmp);
  }
  for (const auto &x : ans) {
    prints(x);
  }
  return 0;
}
