#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int _ = 0; _ < (T); ++_) {
    int n;
    long long int ans = 0;
    priority_queue<pair<long long int, long long int> > que1, que2;
    for (int i = 0; i < (n); ++i) {
      long long int k, l, r;
      cin >> k >> l >> r;
      if (l >= r) {
        ans += r;
        que1.push(pair<long long int, long long int>(k, l - r));
      } else {
        ans += l;
        que2.push(pair<long long int, long long int>(n - k, r - l));
      }
    }
    int m = que1.size();
    int w = que2.size();
    priority_queue<long long int> que;
    for (int i = (m)-1; i >= 0; --i) {
      while (que1.size() > 0 && que1.top().first >= i + 1) {
        que.push(que1.top().second);
        que1.pop();
      }
      if (que.size()) {
        ans += que.top();
        que.pop();
      }
    }
    while (!que.empty()) que.pop();
    for (int i = (w)-1; i >= 0; --i) {
      while (que2.size() > 0 && que2.top().first >= i + 1) {
        que.push(que2.top().second);
        que2.pop();
      }
      if (que.size()) {
        ans += que.top();
        que.pop();
      }
    }
    cout << ans << endl;
  }
  return 0;
}
