#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
int gn(int index, vector<int>& next) {
  if (index >= next.size()) return next.size() + 1;
  if (next[index] = index) return index;
  return next[index] = gn(next[index], next);
}
int gp(int index, vector<int>& prev) {
  if (index < 0) return -1;
  if (prev[index] == index) return index;
  return prev[index] = gp(prev[index], prev);
}
void solve() {
  int n;
  cin >> n;
  vector<int> k(n, 0);
  vector<long long> r(n, 0), l(n, 0);
  for (int i = 0; i < n; i++) cin >> k[i] >> l[i] >> r[i];
  for (int i = 0; i < n; i++) k[i]--;
  vector<vector<long long>> srt(2 * n, vector<long long>(4, 0));
  for (int i = 0; i < n; i++) {
    srt[2 * i] = {l[i], r[i], 0, i};
    srt[2 * i + 1] = {r[i], l[i], 1, i};
  }
  sort(srt.begin(), srt.end(),
       [](const vector<long long>& a, const vector<long long>& b) -> bool {
         return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]);
       });
  vector<int> next(n, 0), prev(n, 0), curr(n, -1);
  vector<bool> v(n, true);
  for (int i = 0; i < n; i++) prev[i] = next[i] = i;
  for (int i = 0; i < srt.size(); i++) {
    if (v[srt[i][3]]) {
      int ind = srt[i][3], pos = k[ind];
      if (srt[i][2] == 0) {
        prev[pos] = gp(pos, prev);
        if (prev[pos] >= 0) {
          curr[ind] = prev[pos];
          prev[prev[pos]] = gp(prev[pos] - 1, prev);
          v[ind] = false;
        }
      } else {
        if (pos + 1 < n) {
          pos++;
          next[pos] = gn(pos, next);
          if (next[pos] < n) {
            curr[ind] = next[pos];
            next[next[pos]] = gn(next[pos] + 1, next);
            v[ind] = false;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (curr[i] == -1)
      cout << "Error\n";
    else
      ans += (curr[i] <= k[i] ? l[i] : r[i]);
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
