#include <bits/stdc++.h>
using namespace std;
int n, k[200200], l[200200], r[200200], p[200200];
vector<pair<int, int> > in[200200];
bool c[200200];
int main() {
  int Test;
  scanf("%d", &Test);
  while (Test--) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d %d %d", &k[i], &l[i], &r[i]);
      if (l[i] > r[i]) in[k[i]].push_back({l[i] - r[i], i});
      p[i] = -1;
      c[i + 1] = 1;
    }
    priority_queue<pair<int, int> > Q;
    for (int i = n; i >= 1; i--) {
      for (auto &x : in[i]) Q.push(x);
      if (!Q.empty()) {
        p[Q.top().second] = i;
        c[i] = 1;
        Q.pop();
      }
      in[i].clear();
    }
    while (!Q.empty()) Q.pop();
    for (int i = 0; i < n; i++)
      if (r[i] > l[i]) in[k[i] + 1].push_back({r[i] - l[i], i});
    for (int i = 1; i <= n; i++) {
      for (auto &x : in[i]) Q.push(x);
      if (!Q.empty()) {
        p[Q.top().second] = i;
        c[i] = 1;
        Q.pop();
      }
      in[i].clear();
    }
    for (int i = 0, j = 1; i < n; i++)
      if (p[i] == -1) {
        while (!c[j]) j++;
        p[i] = j++;
      }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (p[i] <= k[i])
        ans += l[i];
      else
        ans += r[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
