#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long ret = 0;
    vector<vector<long long>> wantFront, wantBack;
    for (int i = 0; i < n; i++) {
      int k, l, r;
      cin >> k >> l >> r;
      if (l >= r) {
        ret += l;
        wantFront.push_back({k, l - r});
      } else {
        ret += r;
        wantBack.push_back({n - k, r - l});
      }
    }
    sort(wantFront.begin(), wantFront.end());
    int next = 0;
    priority_queue<long long> que;
    for (int place = 0; place <= wantFront.size(); place++) {
      while (next < wantFront.size() &&
             (wantFront[next][0] <= place || place == wantFront.size())) {
        que.push(wantFront[next++][1]);
      }
      while (que.size() > place) {
        ret -= que.top();
        que.pop();
      }
    }
    sort(wantBack.begin(), wantBack.end());
    next = 0;
    que = priority_queue<long long>();
    for (int place = 0; place <= wantBack.size(); place++) {
      while (next < wantBack.size() &&
             (wantBack[next][0] <= place || place == wantBack.size())) {
        que.push(wantBack[next++][1]);
      }
      while (que.size() > place) {
        ret -= que.top();
        que.pop();
      }
    }
    cout << ret << endl;
  }
  return 0;
}
