#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  for (int x = 0; x < t; ++x) {
    long long n;
    cin >> n;
    long long sum = 0;
    vector<pair<pair<long long, long long>, long long> > vp;
    set<long long> num;
    for (int i = 0; i < n; ++i) {
      num.insert(i);
      long long k, l, r;
      cin >> k >> l >> r;
      k--;
      sum += r;
      if (l - r >= 0) {
        vp.push_back(make_pair(make_pair(l - r, k), 1));
      } else {
        vp.push_back(make_pair(make_pair(r - l, k), -1));
      }
    }
    sort((vp).rbegin(), (vp).rend());
    long long cm = 0;
    for (int i = 0; i < n; ++i) {
      if (vp[i].second == 1) {
        auto itr = num.upper_bound(vp[i].first.second);
        if (itr == num.begin()) {
        } else {
          itr--;
          sum += vp[i].first.first;
          num.erase(itr);
        }
      } else {
        if (n - cm - 1 <= vp[i].first.second) {
          auto itr = num.end();
          itr--;
          sum -= vp[i].first.first;
          num.erase(itr);
        } else {
          auto itr = num.end();
          itr--;
          num.erase(itr);
        }
        cm++;
      }
    }
    cout << sum << "\n";
  }
  return 0;
}
