#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int T, n;
vector<int> G[maxn], H[maxn];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      G[i].clear(), H[i].clear();
    }
    long long ans = 0;
    for (int i = 1, K, L, R; i <= n; i++) {
      scanf("%d %d %d", &K, &L, &R);
      if (L > R)
        ans += R, G[K].push_back(L - R);
      else
        ans += L, H[K].push_back(R - L);
    }
    multiset<int> S;
    for (int i = 1; i <= n; i++) {
      for (int j : G[i]) {
        S.insert(j), ans += j;
      }
      while (S.size() > i) {
        auto it = S.begin();
        ans -= *it, S.erase(it);
      }
    }
    S.clear();
    for (int i = n; i; i--) {
      for (int j : H[i]) {
        S.insert(j), ans += j;
      }
      while (S.size() > n - i) {
        auto it = S.begin();
        ans -= *it, S.erase(it);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
