#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f;
const long long mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end() {}
int n;
struct camels {
  int k;
  long long l, r;
} a[N];
long long ans;
vector<pair<int, int>> L, R;
priority_queue<int, vector<int>, greater<int>> q;
void solve() {
  ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d%lld%lld", &a[i].k, &a[i].l, &a[i].r);
  for (int i = 1; i <= n; ++i) {
    if (a[i].l == a[i].r)
      ans += a[i].l;
    else if (a[i].l > a[i].r)
      ans += a[i].r, L.push_back(make_pair((a[i].k), (a[i].l - a[i].r)));
    else
      ans += a[i].l, R.push_back(make_pair((n - a[i].k), (a[i].r - a[i].l)));
  }
  sort(L.begin(), L.end()), sort(R.begin(), R.end());
  for (auto i : L) {
    ans += i.second;
    q.push(i.second);
    while (!q.empty() && q.size() > i.first) ans -= q.top(), q.pop();
  }
  while (!q.empty()) q.pop();
  for (auto i : R) {
    ans += i.second;
    q.push(i.second);
    while (!q.empty() && q.size() > i.first) ans -= q.top(), q.pop();
  }
  while (!q.empty()) q.pop();
  cout << ans << '\n';
}
int main() {
  TIME_START = clock();
  int Test = 1;
  cin >> Test;
  while (Test--) solve();
  TIME_END = clock();
  program_end();
  return 0;
}
