#include <bits/stdc++.h>
using namespace std;
string imp = "Impossible\n";
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t startTime;
double getCurrentTime() {
  return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int N = 5e6 + 5;
long long MOD = 1e9 + 7;
long long n, m, k, i, j;
bool f0, f1, f2;
const int MAXN = 2e3;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(11);
  int tests = 1;
  cin >> tests;
  while (tests--) {
    int n;
    cin >> n;
    long long k[n], l[n], r[n];
    priority_queue<pair<int, int> > pq;
    for (int i = 0; i < n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      pq.push({abs(l[i] - r[i]), i});
    }
    set<int> s;
    for (int i = 1; i <= n; i++) s.insert(i);
    long long h = 0;
    while (!pq.empty()) {
      pair<int, int> t = pq.top();
      pq.pop();
      int i = t.second;
      if (l[i] > r[i]) {
        auto ind = s.upper_bound(k[i]);
        if (ind == s.begin()) {
          h += r[i];
        } else {
          ind--;
          h += l[i];
          s.erase(ind);
        }
      } else if (r[i] > l[i]) {
        auto ind = s.upper_bound(k[i]);
        if (ind == s.end()) {
          h += l[i];
        } else {
          h += r[i];
          s.erase(ind);
        }
      } else {
        h += l[i];
      }
    }
    cout << h << "\n";
  }
  return 0;
}
