#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int tt = 0; tt < t; tt++) {
    int n;
    cin >> n;
    vector<int> vl(n, 0), vr(n, 0), vk(n, 0);
    vector<pair<int, int>> vp;
    long long int res = 0;
    for (int i = 0; i < n; i++) {
      cin >> vk[i] >> vl[i] >> vr[i];
      res += max(vl[i], vr[i]);
      vp.push_back(make_pair(abs(vl[i] - vr[i]), i));
    }
    sort(vp.begin(), vp.end());
    reverse(vp.begin(), vp.end());
    int l = 1, r = n;
    int l_max = 1, r_min = n;
    for (int i = 0; i < n; i++) {
      int diff = vp[i].first, index = vp[i].second;
      if (diff == 0) break;
      if (vl[index] > vr[index]) {
        if (l <= vk[index]) {
          l++;
        } else {
          if (vk[index] <= l_max)
            l++;
          else
            res -= diff;
        }
        l_max = max(l_max, vk[index]);
      } else {
        if (r > vk[index]) {
          r--;
        } else {
          if (vk[index] < r_min)
            r--;
          else
            res -= diff;
        }
        r_min = min(r_min, vk[index]);
      }
    }
    cout << res << endl;
  }
}
