#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < (t); ++i) {
    int n;
    cin >> n;
    ll k[n], l[n], r[n], muki[n];
    pair<ll, int> z[n];
    for (int j = 0; j < (n); ++j) {
      cin >> k[j] >> l[j] >> r[j];
      k[j]--;
      z[j].first = abs(l[j] - r[j]);
      z[j].second = j;
      if (l[j] - r[j] > 0) {
        muki[j] = 0;
      } else {
        muki[j] = 1;
      }
    }
    sort(z, z + n, greater<pair<ll, int> >());
    ll ans = 0;
    int filled[n];
    fill(filled, filled + n, -1);
    for (int j = 0; j < (n); ++j) {
      int index = z[j].second;
      if (muki[index] == 0) {
        int tmp = k[index];
        while (tmp >= 0) {
          if (filled[tmp] == -1) {
            filled[tmp] = index;
            ans += l[index];
            break;
          }
          tmp--;
        }
        if (tmp == -1) {
          ans += r[index];
        }
      } else {
        int tmp = k[index] + 1;
        while (tmp < n) {
          if (filled[tmp] == -1) {
            filled[tmp] = index;
            ans += r[index];
            break;
          }
          tmp--;
        }
        if (tmp == n) {
          ans += l[index];
        }
      }
    }
    cout << ans << endl;
  }
}
