#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int t, n;
struct uzi {
  int k, l;
  bool operator<(const uzi& t) const { return k < t.k; }
} L[N], R[N];
int dx, dy;
int main() {
  ios::sync_with_stdio(false);
  for (cin >> t; t; t--) {
    cin >> n;
    long long ans = 0;
    dx = dy = 0;
    for (int i = 1; i <= n; i++) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l > r) {
        ans += r;
        L[++dx] = {k, -l + r};
      } else if (l < r) {
        ans += l;
        R[++dy] = {k, -r + l};
      } else
        ans += l;
    }
    sort(L + 1, L + 1 + dx);
    sort(R + 1, R + 1 + dy);
    int x = 1;
    priority_queue<int> q;
    for (int i = 1; i <= n; i++) {
      while (x <= dx && L[x].k == i) q.push(L[x].l), x++;
      while (q.size() > i) q.pop();
    }
    while (!q.empty()) ans -= q.top(), q.pop();
    x = dy;
    for (int i = n; i >= 1; i--) {
      while (x >= 1 && R[x].k == i) q.push(R[x].l), x--;
      while (q.size() > n - i + 1) q.pop();
    }
    while (!q.empty()) ans -= q.top(), q.pop();
    cout << ans << '\n';
  }
  return 0;
}
