#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
struct node {
  int d, k, l, r;
  bool operator<(const node& o) const {
    if (d == o.d) {
      if (k == o.k) {
        if (l == o.l) return r < o.r;
        return l > o.l;
      }
      return k < o.k;
    }
    return d < o.d;
  }
} camel[N];
int n;
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l >= r)
        camel[i] = {1, k, l, r};
      else
        camel[i] = {2, n - k, r, l};
    }
    sort(camel, camel + n);
    int res = 0;
    for (int i = 0; i < n; i++) {
      if (camel[i].d == 1) {
        if (i < camel[i].k)
          res += camel[i].l;
        else
          res += camel[i].r;
      } else {
        if (n - i <= camel[i].k)
          res += camel[i].l;
        else
          res += camel[i].r;
      }
    }
    cout << res << endl;
  }
  return 0;
}
