#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long T;
  cin >> T;
  for (long long testcase = 0; testcase < T; ++testcase) {
    long long N;
    cin >> N;
    vector<vector<long long>> left(N);
    vector<vector<long long>> right(N);
    long long ans = 0;
    for (long long i = 0; i < N; ++i) {
      long long K, L, R;
      cin >> K >> L >> R;
      K -= 1;
      ans += min(L, R);
      if (L > R) {
        left.at(K).push_back(L - R);
      } else {
        if (K != N - 1) {
          right.at(K + 1).push_back(R - L);
        }
      }
    }
    multiset<long long> ls;
    for (long long i = 0; i < N; ++i) {
      for (long long j = 0; j < left.at(i).size(); ++j) {
        ls.insert(left.at(i).at(j));
      }
      while (ls.size() > (i + 1)) {
        ls.erase(ls.begin());
      }
    }
    for (auto itr = ls.begin(); itr != ls.end(); ++itr) {
      ans += *(itr);
    }
    multiset<long long> rs;
    for (long long i = 0; i < N; ++i) {
      for (long long j = 0; j < right.at(i).size(); ++j) {
        rs.insert(right.at(i).at(j));
      }
      while (rs.size() > (i + 1)) {
        rs.erase(rs.begin());
      }
    }
    for (auto itr = rs.begin(); itr != rs.end(); ++itr) {
      ans += *(itr);
    }
    cout << ans << "\n";
  }
}
