#include <bits/stdc++.h>
using namespace std;
vector<long long> p[200005], c[200005];
int main() {
  int o;
  cin >> o;
  while (o--) {
    long long n, ans = 0;
    cin >> n;
    priority_queue<long long, vector<long long>, greater<long long>> q;
    for (long long i = 1; i <= n; i++) {
      long long k, l, r;
      cin >> k >> l >> r;
      if (l > r) p[k].push_back(l - r), ans += r;
      if (l < r) c[n - k].push_back(r - l), ans += l;
      if (l == r) ans += l;
    }
    for (int i = 1; i <= n; i++) {
      for (auto j : p[i]) {
        q.push(j);
      }
      while (q.size() > i) {
        q.pop();
      }
    }
    while (q.size()) {
      ans += q.top();
      q.pop();
    }
    for (int i = 1; i <= n; i++) {
      for (auto j : c[i]) {
        q.push(j);
      }
      while (q.size() > i) {
        q.pop();
      }
    }
    while (q.size()) {
      ans += q.top();
      q.pop();
    }
    cout << ans << endl;
  }
}
