#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
long long newmod(long long a, long long b) { return ((a % b) + b) % b; }
long long powM(long long a, long long b, long long m) {
  if (m <= 1) return 0;
  a %= m;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
template <typename T, typename F>
void chmax(T &a, F b) {
  if (b > a) a = b;
}
template <typename T, typename F>
void chmin(T &a, F b) {
  if (b < a) a = b;
}
const long long N = 1e4 + 5;
long long vis[N];
vector<pair<long, long> > arr[N];
long long d[N];
struct cmp {
  bool operator()(pair<long, long> a, pair<long, long> b) const {
    return a.first > b.first;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> profit[n + 1], loss[n + 2];
    vector<long long> k(n + 1), l(n + 1), r(n + 1);
    vector<long long> allot(n + 1);
    for (int i = 1; i <= n; i++) {
      cin >> k[i] >> l[i] >> r[i];
      profit[k[i]].push_back(i);
      loss[k[i] + 1].push_back(i);
    }
    set<pair<long, long> > s;
    for (int i = n; i >= 1; i--) {
      for (auto ind : profit[i]) {
        s.insert({l[ind] - r[ind], ind});
      }
      if (!s.empty()) {
        auto it = s.rbegin();
        if ((*it).first > 0) {
          allot[(*it).second] = 1;
          s.erase(*it);
        }
      }
    }
    for (int i = 2; i <= n; i++) {
      for (auto ind : loss[i]) {
        s.insert({r[ind] - l[ind], ind});
      }
      if (!s.empty()) {
        auto it = s.rbegin();
        if ((*it).first > 0) {
          allot[(*it).second] = 1;
          s.erase(*it);
        }
      }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!allot[i])
        ans += min(l[i], r[i]);
      else
        ans += max(l[i], r[i]);
    }
    cout << ans << "\n";
  }
  return 0;
}
