#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  long long T, t;
  cin >> T;
  for (t = (0); t < (T); ++t) {
    long long N, i;
    cin >> N;
    set<pair<long long, long long>, greater<pair<long long, long long>>> vals;
    vector<long long> K(N), L(N), R(N);
    for (i = (0); i < (N); ++i) {
      cin >> K[i] >> L[i] >> R[i];
    }
    for (i = (0); i < (N); ++i) {
      if (K[i] == N) {
        R[i] = L[i];
      }
      if (L[i] >= R[i]) {
        vals.insert({L[i] - R[i], i});
      } else {
        vals.insert({R[i] - L[i], i});
      }
    }
    long long ans = 0;
    set<long long> positions;
    for (i = (0); i < (N); ++i) {
      positions.insert(i);
    }
    for (auto it = vals.begin(); it != vals.end(); ++it) {
      long long idx = it->second;
      if (L[idx] >= R[idx]) {
        auto bound = positions.upper_bound(K[idx] - 1);
        if (bound == positions.begin()) {
          ans += R[idx];
        } else {
          bound--;
          ans += L[idx];
          positions.erase(bound);
        }
      } else {
        auto bound = positions.lower_bound(K[idx]);
        if (bound == positions.end()) {
          ans += L[idx];
        } else {
          ans += R[idx];
          positions.erase(bound);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
