#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 10000000000;
int main() {
  int T;
  cin >> T;
  for (int i = 0; (i) < ((int)(T)); ++(i)) {
    int N;
    cin >> N;
    vector<ll> K(N), L(N), R(N), D(N);
    for (int j = 0; (j) < ((int)(N)); ++(j)) {
      cin >> K[j] >> L[j] >> R[j];
      D[j] = L[j] - R[j];
    }
    int ans = 0;
    vector<int> pos(N, 0);
    for (int j = 0; (j) < ((int)(N)); ++(j)) {
      int index = min_element(D.begin(), D.end()) - D.begin();
      if (L[index] > R[index]) {
        int n = K[index] - 1;
        while (pos[n] != 0 && n >= 0) {
          n--;
        }
        if (n < 0)
          ans += R[index];
        else {
          ans += L[index];
          pos[n] = index + 1;
        }
      } else {
        int n = N - 1;
        while (pos[n] != 0) {
          n--;
        }
        if (n < K[index])
          ans += L[index];
        else {
          ans += R[index];
          pos[n] = index + 1;
        }
      }
      D[index] = INF;
    }
    cout << ans << endl;
  }
}
