#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  int t;
  cin >> t;
  for (int _ = 0; _ < (t); _++) {
    int n;
    cin >> n;
    vector<vector<int>> diff(n + 1);
    long long ans = 0;
    for (int i = 0; i < (n); i++) {
      int k, l, r;
      cin >> k >> l >> r;
      diff[k].push_back(l - r);
      ans += r;
    }
    priority_queue<int, vector<int>, greater<int>> q;
    for (int i = 0; i < (n); i++) {
      if (!q.empty() && !diff[i + 1].empty() && q.top() < 0) {
        q.pop();
        q.push(0);
      }
      for (auto l : diff[i + 1]) q.push(l);
      while (q.size() > i + 1) q.pop();
    }
    while (!q.empty()) {
      ans += q.top();
      q.pop();
    }
    cout << ans << endl;
  }
  return 0;
}
