#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
int n, p[N], l[N], r[N], idx[N];
bool coo(int i, int j) { return l[i] - r[i] < l[j] - r[j]; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      idx[i] = i;
      cin >> p[i] >> l[i] >> r[i];
    }
    sort(idx + 1, idx + n + 1, coo);
    set<int> s;
    for (int i = 1; i <= n; i++) {
      s.insert(i);
    }
    long long sol = 0;
    for (int j = 1; j <= n; j++) {
      int i = idx[j];
      if (l[i] > r[i]) {
        auto it = s.lower_bound(p[i] + 1);
        if (it != s.begin()) {
          it--;
          s.erase(it);
          sol += l[i];
        } else {
          s.erase(it);
          sol += r[i];
        }
      } else {
        auto it = s.lower_bound(p[i] + 1);
        if (it != s.end()) {
          s.erase(it);
          sol += r[i];
        } else {
          it--;
          s.erase(it);
          sol += l[i];
        }
      }
    }
    cout << sol << "\n";
  }
  return 0;
}
