#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
struct camel {
  ll k;
  ll l;
  ll r;
  bool done = false;
};
bool operator>(const camel &c1, const camel &c2) {
  if (c1.k != c2.k) return c1.k > c2.k;
  return (c1.l) - (c1.r) < (c2.l) - (c2.r);
};
bool operator<(const camel &c1, const camel &c2) {
  if (c1.k != c2.k) return c1.k < c2.k;
  return (c1.l) - (c1.r) > (c2.l) - (c2.r);
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  for (int t1 = 0; t1 < t; t1++) {
    int n;
    cin >> n;
    vector<camel> camels(n);
    for (int i = 0; i < n; i++)
      cin >> camels[i].k >> camels[i].l >> camels[i].r;
    ll ans = 0;
    priority_queue<pll, vector<pll>> que;
    bool fin = false;
    for (ll i = 0; i < n; i++) que.push(pll(camels[i].l - camels[i].r, i));
    for (int i = 0; i < n; i++) {
      while (1) {
        if (que.empty()) {
          fin = true;
          break;
        }
        pll p = que.top();
        que.pop();
        if (p.first < 0) {
          fin = true;
          break;
        }
        if (camels[p.second].k >= i + 1) {
          ans += camels[p.second].l;
          camels[p.second].done = true;
          cout << "get1: " << camels[p.second].l << endl;
          break;
        }
      }
      if (fin) break;
    }
    priority_queue<pll, vector<pll>> queb;
    fin = false;
    for (ll i = 0; i < n; i++)
      if (!camels[i].done) queb.push(pll(camels[i].r - camels[i].l, i));
    for (int i = n - 1; i >= 0; i--) {
      while (1) {
        if (queb.empty()) {
          fin = true;
          break;
        }
        pll p = queb.top();
        queb.pop();
        if (p.first < 0) {
          fin = true;
          break;
        }
        if (camels[p.second].k > i + 1) {
          ans += camels[p.second].r;
          camels[p.second].done = true;
          cout << "get1: " << camels[p.second].r << endl;
          break;
        } else {
          ans += camels[p.second].r;
          camels[p.second].done = true;
          cout << "get1: " << camels[p.second].r << endl;
          break;
        }
      }
      if (fin) break;
    }
    for (int i = 0; i < n; i++)
      if (!camels[i].done) ans += max(camels[i].l, camels[i].r);
    cout << ans << endl;
  }
}
