#include <bits/stdc++.h>
using namespace std;
template <class T>
struct fenwick {
  vector<T> t;
  fenwick(int n) : t(n) {}
  void add(int i, T value) {
    for (; i < t.size(); i |= i + 1) t[i] += value;
  }
  T sum(int i) {
    T res{};
    for (; i >= 0; i = (i & (i + 1)) - 1) res += t[i];
    return res;
  }
};
void solve(istream& in, ostream& out) {
  int t;
  in >> t;
  while (t--) {
    int n;
    in >> n;
    vector<int> K(n), L(n), R(n);
    vector<pair<int, int>> left, right;
    long long res = 0;
    for (int i = 0; i < n; ++i) {
      in >> K[i] >> L[i] >> R[i];
      if (L[i] > R[i])
        left.emplace_back(L[i] - R[i], i);
      else
        right.emplace_back(R[i] - L[i], i);
    }
    sort(left.rbegin(), left.rend());
    sort(right.rbegin(), right.rend());
    fenwick<int> fl(n);
    for (auto [_, i] : left) {
      if (fl.sum(K[i] - 1) < K[i]) {
        fl.add(K[i] - 1, 1);
        res += L[i];
      } else {
        res += R[i];
      }
    }
    fenwick<int> fr(n);
    for (auto [_, i] : right) {
      if (fr.sum(n - K[i]) < n - K[i]) {
        fr.add(n - K[i], 1);
        res += R[i];
      } else {
        res += L[i];
      }
    }
    out << res << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solve(in, out);
}
