#include <bits/stdc++.h>
using namespace std;
const long long N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  if (0) return;
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  if (0) return;
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long n;
struct camel {
  long long k, l, r, val;
};
void solve() {
  cin >> n;
  vector<camel> vec(n + 1);
  set<pair<long long, long long> > st;
  long long lcnt = 0, rcnt = 0;
  for (long long i = 1; i < (long long)n + 1; i++) {
    cin >> vec[i].k >> vec[i].l >> vec[i].r;
    if (vec[i].l >= vec[i].r)
      lcnt++;
    else
      rcnt++;
    long long val = abs(vec[i].l - vec[i].r);
    st.insert({val, i});
  }
  set<long long> l, r;
  long long p = 0, idx = 1;
  while (p < lcnt) {
    l.insert(idx);
    idx++;
    p++;
  }
  p = 0;
  while (p < rcnt) {
    r.insert(idx);
    p++;
    idx++;
  }
  auto it = st.end();
  it--;
  long long ans = 0;
  while (1) {
    long long id = it->second;
    long long val = vec[id].l - vec[id].r;
    long long k = vec[id].k;
    if (val >= 0) {
      auto jt = l.lower_bound(k);
      if (jt == l.begin())
        ;
      else if (jt == l.end() or *jt > k)
        jt--;
      if (*jt <= k)
        ans += vec[id].l;
      else
        ans += vec[id].r;
      l.erase(*jt);
    } else {
      auto jt = r.lower_bound(k + 1);
      if (jt != r.end()) {
        ans += vec[id].r;
      } else {
        jt--;
        ans += vec[id].l;
      }
      r.erase(*jt);
    }
    if (it == st.begin())
      break;
    else
      it--;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) solve();
}
