#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int k[200000];
    long long l[200000];
    long long r[200000];
    cin >> n;
    vector<pair<int, int> > a, b, c;
    for (int i = 0; i < n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      k[i]--;
      if (l[i] > r[i]) {
        a.push_back(make_pair(k[i], i));
      } else if (l[i] < r[i]) {
        b.push_back(make_pair(k[i], i));
      } else {
        c.push_back(make_pair(k[i], i));
      }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for (int i = 0; i < c.size(); i++) {
      a.push_back(c[i]);
    }
    for (int i = 0; i < b.size(); i++) {
      a.push_back(b[i]);
    }
    long long ans = 0;
    for (int i = 0; i < a.size(); i++) {
      if (i <= k[a[i].second]) {
        ans += l[a[i].second];
      } else {
        ans += r[a[i].second];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
