#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int MAXN = 1000005, MAXM = 30000000;
int P;
char _buf[1048576], *S, *T, _buf1[1048576], *S1 = _buf1;
inline char gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, 1048576, stdin);
    if (S == T) return 0;
  }
  return *S++;
}
template <class T>
void get(T &x) {
  char c;
  for (c = gc(); (c < '0' || c > '9') && c != '-'; c = gc())
    ;
  bool b = 0;
  if (c == '-') {
    b = 1;
    c = gc();
  }
  for (x = c ^ '0', c = gc(); c >= '0' && c <= '9'; c = gc())
    x = (x << 3) + (x << 1) + (c ^ '0');
  if (b) x = -x;
}
inline void pc(char c) {
  if (S1 == _buf1 + 1048576) {
    fwrite(_buf1, 1, 1048576, stdout);
    S1 = _buf1;
  }
  *S1++ = c;
}
void out(long long x) {
  if (x > 9) out(x / 10);
  pc(x % 10 ^ '0');
}
int Pow(int x, int y) {
  int s = 1;
  for (; y; y >>= 1, x = (long long)x * x % P)
    if (y & 1) s = (long long)s * x % P;
  return s;
}
int A(int x) { return x < 0 ? -x : x; }
set<int> s;
set<int>::iterator it;
int t, n, i, j, a[MAXN], b[MAXN], c[MAXN], p[MAXN];
bool cmp(int x, int y) { return A(b[x] - c[x]) > A(b[y] - c[y]); }
long long ans;
int main() {
  get(t);
  while (t--) {
    get(n);
    s.clear();
    for (i = 1; i <= n; i++) {
      get(a[i]);
      get(b[i]);
      get(c[i]);
      p[i] = i;
      s.insert(i);
    }
    sort(p + 1, p + n + 1, cmp);
    ans = 0;
    for (i = 1; i <= n; i++)
      if (b[p[i]] > c[p[i]]) {
        it = s.upper_bound(a[p[i]]);
        if (it == s.begin()) {
          ans += c[p[i]];
          continue;
        }
        it--;
        s.erase(it);
        ans += b[p[i]];
      } else if (b[p[i]] < c[p[i]]) {
        it = s.upper_bound(a[p[i]]);
        if (it == s.end()) {
          ans += b[p[i]];
          continue;
        }
        s.erase(it);
        ans += c[p[i]];
      } else
        ans += c[p[i]];
    out(ans);
    pc('\n');
  }
  fwrite(_buf1, 1, S1 - _buf1, stdout);
  return 0;
}
