#include <bits/stdc++.h>
using namespace std;
bool sortcol(const vector<int>& v1, const vector<int>& v2) {
  return v1[0] < v2[0];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, x, y, z, p, q, s;
    p = 0;
    q = 0;
    s = 0;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
      cin >> x >> y >> z;
      a[i][0] = x;
      a[i][1] = y;
      a[i][2] = z;
    }
    sort(a.begin(), a.end(), sortcol);
    for (int i = 0; i < n; i++) {
      if (a[i][1] >= a[i][2]) {
        if (a[i][0] > p) {
          s = s + a[i][1];
          p = p + 1;
        } else {
          s = s + a[i][2];
          q = q + 1;
        }
      } else {
        if (n - a[i][0] > q) {
          s = s + a[i][2];
          q = q + 1;
        } else {
          s = s + a[i][1];
          p = p + 1;
        }
      }
    }
    cout << s << endl;
  }
}
