#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int inf = (1 << 30) - 1;
const int mod = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> k(n), l(n), r(n);
    vector<pair<long long, long long>> p(n);
    for (int i = 0; i < (n); ++i) {
      cin >> k[i] >> l[i] >> r[i];
      k[i]--;
      p[i] = {abs(l[i] - r[i]), i};
    }
    sort((p).begin(), (p).end());
    reverse((p).begin(), (p).end());
    int s = 0, t = n - 1;
    set<int> st;
    long long sum = 0;
    for (auto x : p) {
      long long u = x.first, v = x.second;
      if (l[v] - r[v] >= 0) {
        auto itr = st.lower_bound(k[v]);
        int s = *itr;
        if (s == 1) {
          sum += r[v];
          t--;
        } else {
          sum += l[v];
          st.erase(s);
        }
      } else {
        if (t > k[v]) {
          sum += r[v];
        } else {
          sum += l[v];
        }
        t--;
      }
    }
    cout << sum << endl;
  }
}
