#include <bits/stdc++.h>
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;
}
using ll = long long;
using namespace std;
int main() {
  ll t;
  cin >> t;
  for (int count = 0; count < (t); count++) {
    ll n;
    cin >> n;
    vector<pair<ll, ll>> right, left;
    ll ans = 0;
    for (int i = 0; i < (n); i++) {
      ll k, l, r;
      cin >> k >> l >> r;
      if (l < r) {
        ans += l;
        right.push_back(make_pair(n - k, r - l));
      } else if (l > r) {
        ans += r;
        left.push_back(make_pair(k, l - r));
      } else
        ans += l;
    }
    if ((int)right.size()) sort(right.begin(), right.end());
    if ((int)left.size()) sort(left.begin(), left.end());
    priority_queue<ll, vector<ll>, greater<ll>> que1, que2;
    for (int i = 0; i < ((int)right.size()); i++) {
      if (que1.size() < right[i].first) {
        ans += right[i].second;
        que1.push(right[i].second);
      } else if (que1.top() < right[i].second) {
        ans -= que1.top();
        que1.pop();
        ans += right[i].second;
        que1.push(right[i].second);
      }
    }
    for (int i = 0; i < ((int)left.size()); i++) {
      if (que2.size() < left[i].first) {
        ans += left[i].second;
        que2.push(left[i].second);
      } else if (que2.top() < left[i].second) {
        ans -= que2.top();
        que2.pop();
        ans += left[i].second;
        que2.push(left[i].second);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
