#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> k(n), l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> k[i] >> l[i] >> r[i];
  }
  long long int ans = 0;
  priority_queue<pair<long long int, long long int>> q;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      qq;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      less;
  for (int i = 0; i < n; i++) {
    if (l[i] - r[i] > 0) {
      q.push({k[i], l[i] - r[i]});
      ans += r[i];
    } else {
      qq.push({k[i], r[i] - l[i]});
      ans += l[i];
    }
  }
  multiset<long long int> s;
  queue<long long int> tmpQ;
  long long int cnt = 0;
  for (long long int i = n; i >= 1; i--) {
    while (q.size() && q.top().first >= i) {
      s.insert(q.top().second);
      q.pop();
    }
    if (s.size() == 0) continue;
    ans += (*s.begin());
    tmpQ.push((*s.begin()));
    s.erase(s.begin());
  }
  long long int tmpC = 0;
  multiset<long long int, greater<long long int>> lessSet;
  while (tmpQ.size()) {
    tmpC++;
    lessSet.insert(tmpQ.front());
    less.push({tmpC, tmpQ.front()});
    tmpQ.pop();
  }
  if (0)
    cout << "ans"
         << "=" << ans << " " << endl;
  ;
  s.clear();
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      lessTQ;
  for (long long int i = 1; i <= n; i++) {
    while (qq.size() && qq.top().first < i) {
      s.insert(qq.top().second);
      qq.pop();
    }
    if (0)
      cout << "i"
           << "=" << i << " "
           << "(*s.begin())"
           << "=" << (*s.begin()) << " "
           << "(*lessSet.begin())"
           << "=" << (*lessSet.begin()) << endl;
    ;
    while (less.size() && less.top().first >= i) {
      auto itr = lessSet.find(less.top().second);
      lessSet.erase(itr);
      less.pop();
    }
    if (s.size() == 0) continue;
    if (lessSet.size()) {
      long long int nowTop = (*s.begin());
      long long int targetTop = (*lessSet.begin());
      if (nowTop < targetTop) continue;
      ans -= targetTop;
      ans += nowTop;
      s.erase(s.begin());
    } else {
      long long int nowTop = (*s.begin());
      ans += nowTop;
      s.erase(s.begin());
    }
  }
  cout << ans << endl;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
