#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<pair<int, int>> kl, kr;
    long long total = 0;
    for (int j = 0; j < n; j++) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l > r) {
        kl.push_back({l - r, k - 1});
        total += r;
      } else if (r > l) {
        kr.push_back({r - l, n - k});
        total += l;
      } else
        total += l;
    }
    sort(kl.rbegin(), kl.rend());
    sort(kr.rbegin(), kr.rend());
    int klsize = kl.size(), krsize = kr.size();
    vector<int> resl(klsize), resr(krsize);
    for (int j = 0; j < klsize; j++) {
      bool flg = true;
      if (kl[j].second >= klsize) {
        kl[j].second = klsize - 1;
      }
      while (resl[kl[j].second] != 0) {
        kl[j].second--;
        if (kl[j].second < 0) {
          kl[j].second += klsize;
          flg = false;
        }
      }
      resl[kl[j].second] = 1;
      if (flg) total += kl[j].first;
    }
    for (int j = 0; j < krsize; j++) {
      bool flg = true;
      if (kr[j].second >= krsize) {
        kr[j].second = krsize - 1;
      }
      while (resr[kr[j].second] != 0) {
        kr[j].second--;
        if (kr[j].second < 0) {
          kr[j].second += krsize;
          flg = false;
        }
      }
      resr[kr[j].second] = 1;
      if (flg) total += kr[j].first;
    }
    cout << total << endl;
  }
  return 0;
}
