#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
int n;
vector<int> wl[maxN], wr[maxN];
void process() {
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int k, l, r;
    cin >> k >> l >> r;
    if (l >= r) {
      wl[k].push_back(l - r);
    } else {
      wr[n - k].push_back(r - l);
    }
    ans = ans + min(l, r);
  }
  priority_queue<int> pq;
  for (int i = 1; i <= n; ++i) {
    for (auto v : wl[i]) {
      pq.push(v);
      ans += v;
    }
    while (pq.size() > i) {
      int x = pq.top();
      pq.pop();
      ans -= x;
    }
  }
  while (!pq.empty()) pq.pop();
  for (int i = 1; i <= n; ++i) {
    for (auto v : wr[i]) {
      pq.push(v);
      ans += v;
    }
    while (pq.size() > i) {
      int x = pq.top();
      pq.pop();
      ans -= x;
    }
  }
  cout << ans << '\n';
  for (int i = 1; i <= n; ++i) {
    wl[i].clear();
    wr[i].clear();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) process();
  return 0;
}
