#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n;
long long k[N], l[N], r[N];
vector<pair<long long, long long> > store[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) store[i].clear();
    long long ans = 0;
    multiset<pair<long long, long long> > s;
    for (long long i = 1; i <= n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      ans += r[i];
      store[k[i]].push_back({l[i] - r[i], i});
    }
    long long have = 0;
    for (long long i = 1; i <= n; i++) {
      have++;
      for (auto &it : store[i]) s.insert(it);
      while (have && s.size() > 0 && s.rbegin()->first > 0) {
        have--;
        ans += s.rbegin()->first;
        s.erase(--s.end());
      }
      if (i == n) {
        while (have && s.size() > 0) {
          have--;
          ans += s.rbegin()->first;
          s.erase(--s.end());
        }
      }
      for (auto &it : store[i]) {
        if (s.find(it) != s.end()) {
          s.erase(it);
          s.insert({0, it.second});
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
