#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 nowAns = -(1LL << 50);
  {
    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;
    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;
    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());
      s.erase(s.begin());
    }
    s.clear();
    for (long long int i = cnt + 1; i <= n; i++) {
      while (qq.size() && qq.top().first < i) {
        s.insert(qq.top().second);
        qq.pop();
      }
      if (s.size() == 0) continue;
      ans += (*s.begin());
      s.erase(s.begin());
    }
    chmax(nowAns, ans);
  }
  {
    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;
    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;
    long long int cnt = 0;
    for (long long int i = 1; i <= n; i++) {
      while (qq.size() && qq.top().first < i) {
        s.insert(qq.top().second);
        qq.pop();
      }
      if (s.size() == 0) continue;
      ans += (*s.begin());
      s.erase(s.begin());
    }
    s.clear();
    for (long long int i = n - cnt; 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());
      s.erase(s.begin());
    }
    chmax(nowAns, ans);
  }
  cout << nowAns << endl;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
