#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll ans[100000];
bool compP(P p1, P p2) { return p1.first > p2.first; }
bool comp(int a, int b) { return a > b; }
int main() {
  int t;
  cin >> t;
  priority_queue<P, vector<P>, decltype(&compP)> Ql(compP), Qr(compP);
  priority_queue<int, vector<int>, decltype(&comp)> Sl(comp), Sr(comp);
  for (int j = 0; j < (t); ++j) {
    int n, ln = 0, rn = 0;
    ans[j] = 0;
    cin >> n;
    for (int i = 0; i < (n); ++i) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l == r)
        ans[j] += l;
      else if (l > r) {
        ans[j] += r;
        ln++;
        Ql.push(make_pair(k - 1, l - r));
      } else {
        ans[j] += l;
        rn++;
        if (k < n) Qr.push(make_pair(n - 1 - k, r - l));
      }
    }
    for (int i = 0; i < (ln); ++i) {
      int ln2 = 0;
      while (!Ql.empty() && Ql.top().first == i) {
        Sl.push(Ql.top().second);
        ln2++;
        Ql.pop();
      }
      while (ln2 > i + 1) {
        Sl.pop();
      }
    }
    while (!Ql.empty()) {
      int l = Ql.top().second;
      Ql.pop();
      ans[j] += l;
    }
    while (!Sl.empty()) {
      ans[j] += Sl.top();
      Sl.pop();
    }
    for (int i = 0; i < (rn); ++i) {
      int rn2 = 0;
      while (!Qr.empty() && Qr.top().first == i) {
        Sr.push(Qr.top().second);
        rn2++;
        Qr.pop();
      }
      while (rn2 > i + 1) {
        Sr.pop();
      }
    }
    while (!Qr.empty()) {
      int r = Qr.top().second;
      Qr.pop();
      ans[j] += r;
    }
    while (!Sr.empty()) {
      ans[j] += Sr.top();
      Sr.pop();
    }
  }
  for (int i = 0; i < (t); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
