#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
struct node {
  int k;
  long long v;
} a[N];
int n, n1, n2;
long long ans;
bool operator<(node a, node b) { return a.k == b.k ? a.v < b.v : a.k > b.k; }
priority_queue<node> q1, q2;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    ans = n1 = n2 = 0, scanf("%d", &n);
    for (int i = 1, k; i <= n; i++) {
      long long l, r;
      scanf("%d%lld%lld", &k, &l, &r);
      if (l > r)
        ans += r, ++n1, q1.push((node){k, l - r});
      else if (l == r)
        ans += l;
      else
        ans += l, ++n2, q2.push((node){n - k, r - l});
    }
    for (int i = 1; i <= n1; i++) {
      while (!q1.empty() && q1.top().k < i) q1.pop();
      if (!q1.empty()) ans += q1.top().v, q1.pop();
    }
    while (!q1.empty()) q1.pop();
    for (int i = 1; i <= n2; i++) {
      while (!q2.empty() && q2.top().k < i) q2.pop();
      if (!q2.empty()) ans += q2.top().v, q2.pop();
    }
    while (!q2.empty()) q2.pop();
    printf("%lld\n", ans);
  }
}
