#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 += r;
        wantFront.push_back({k - 1, -(l - r)});
      } else {
        ret += l;
        wantBack.push_back({n - k - 1, -(r - l)});
      }
    }
    sort(wantFront.begin(), wantFront.end());
    for (int i = 0; i < wantFront.size(); i++) {
      if (wantFront[i][0] >= i) ret += -wantFront[i][1];
    }
    sort(wantBack.begin(), wantBack.end());
    for (int i = 0; i < wantBack.size(); i++) {
      if (wantBack[i][0] >= i) ret += -wantBack[i][1];
    }
    cout << ret << endl;
  }
  return 0;
}
