#include <bits/stdc++.h>
using namespace std;
int tac;
int n;
int k[200010], l[200010], r[200010];
vector<pair<int, int> > v[3];
int a[200010];
set<int> st;
int main() {
  scanf("%d", &tac);
  while (tac--) {
    scanf("%d", &n);
    for (int i = 0; i < 3; i++) v[i].clear();
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &k[i], &l[i], &r[i]);
      if (l[i] > r[i])
        v[0].push_back(make_pair(r[i] - l[i], i));
      else if (l[i] < r[i])
        v[1].push_back(make_pair(l[i] - r[i], i));
      else
        v[2].push_back(make_pair(0, i));
    }
    sort(v[0].begin(), v[0].end());
    sort(v[1].begin(), v[1].end());
    vector<int> vr;
    st.clear();
    for (int i = 0; i < n; i++) a[i] = -1, st.insert(i);
    int ta = n - 1;
    for (int i = 0; i < v[0].size(); i++) {
      int t = v[0][i].second;
      set<int>::iterator it = st.upper_bound(k[t] - 1);
      if (it != st.begin())
        it--, a[*it] = t, st.erase(it);
      else
        a[ta] = t, st.erase(ta), ta--;
    }
    for (int i = 0; i < n; i++)
      if (a[i] != -1) vr.push_back(a[i]);
    for (int i = 0; i < v[2].size(); i++) vr.push_back(v[2][i].second);
    for (int i = 0; i < n; i++) a[i] = -1, st.insert(i);
    ta = 0;
    for (int i = 0; i < v[1].size(); i++) {
      int t = v[1][i].second;
      set<int>::iterator it = st.lower_bound(k[t]);
      if (it != st.end())
        a[*it] = t, st.erase(it);
      else
        a[ta] = t, st.erase(ta), ta++;
    }
    for (int i = 0; i < n; i++)
      if (a[i] != -1) vr.push_back(a[i]);
    long long res = 0;
    for (int i = 0; i < n; i++) {
      int t = vr[i];
      if (i < k[t])
        res += l[t];
      else
        res += r[t];
    }
    printf("%lld\n", res);
  }
  return 0;
}
