#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
bool cmp(const vector<long long> &a, const vector<long long> &b) {
  return a[0] > b[0];
}
int main() {
  long long t;
  cin >> t;
  for (long long i = 0; i < (long long)(t); i++) {
    ans = 0;
    long long n;
    cin >> n;
    vector<vector<long long>> v(n, vector<long long>(5, 0));
    long long cn = 0;
    for (long long i = 0; i < (long long)(n); i++) {
      long long a, b, c;
      cin >> a >> b >> c;
      a--;
      if (b >= c) {
        v[i][0] = b - c;
        v[i][1] = 0;
        v[i][4] = 0;
        ans += c;
        cn++;
      } else {
        v[i][0] = c - b;
        v[i][1] = 1;
        v[i][4] = 0;
        ans += b;
      }
      v[i][2] = i;
      v[i][3] = a;
    }
    sort(v.begin(), v.end(), cmp);
    set<long long> s, ss;
    for (long long i = 0; i < (long long)(cn); i++) s.insert(i);
    for (long long i = 0; i < (long long)(n - cn); i++) ss.insert(i + cn);
    for (long long i = 0; i < (long long)(n); i++) {
      auto d = v[i];
      if (d[1] == 0) {
        auto itr = s.upper_bound(d[3]);
        if (itr == s.begin()) {
          ans += d[4];
          auto itr = s.end();
          itr--;
          s.erase(itr);
          continue;
        }
        itr--;
        s.erase(itr);
        ans += d[0];
      } else {
        auto itr = ss.upper_bound(d[3]);
        if (itr == ss.end()) {
          ans += d[4];
          auto itr = ss.end();
          itr--;
          ss.erase(itr);
          continue;
        }
        ss.erase(itr);
        ans += d[0];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
