#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 5;
vector<long long> v1[MAXN];
vector<long long> v2[MAXN];
priority_queue<pair<long long, long long>> pq;
bool visited[MAXN];
long long k[MAXN];
long long l[MAXN];
long long r[MAXN];
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      v1[i].clear();
      v2[i].clear();
    }
    for (long long i = 1; i <= n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      visited[i] = false;
      v1[k[i]].push_back(i);
      v2[k[i] + 1].push_back(i);
    }
    while (pq.size()) {
      pq.pop();
    }
    for (long long i = n; i >= 1; i--) {
      for (long long x : v1[i]) {
        pq.push(make_pair(l[x] - r[x], x));
      }
      if (pq.size()) {
        auto hold = pq.top();
        pq.pop();
        if (hold.first > 0) {
          visited[hold.second] = true;
        }
      }
    }
    for (long long i = 1; i <= n; i++) {
      for (long long x : v2[i]) {
        pq.push(make_pair(r[x] - l[x], x));
      }
      if (pq.size()) {
        auto hold = pq.top();
        pq.pop();
        if (hold.first > 0) {
          visited[hold.second] = true;
        }
      }
    }
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      if (visited[i]) {
        ans += max(l[i], r[i]);
      } else {
        ans += min(l[i], r[i]);
      }
    }
    cout << ans << endl;
  }
}
