#include <bits/stdc++.h>
using namespace std;
vector<long long> ans(0, 0);
;
class Rakuda {
 public:
  int index = 0;
  int K = 0;
  int L = 0;
  int R = 0;
  int D = 0;
  void calcD() { D = L - R; }
  bool operator<(const Rakuda &another) const {
    if (K != another.K) return K < another.K;
    if (D != another.D)
      return D < another.D;
    else
      return false;
  }
};
void func() {
  int N;
  cin >> N;
  vector<Rakuda> R(N);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    cin >> R[i].K >> R[i].L >> R[i].R;
    R[i].calcD();
    R[i].index = i;
  }
  sort(R.begin(), R.end());
  long long anss = 0;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    if (R[i].K <= i + 1)
      anss += R[i].L;
    else
      anss += R[i].R;
  }
  ans.push_back(anss);
}
void Main() {
  int T;
  cin >> T;
  for (int i = 0, i_len = (T); i < i_len; ++i) {
    func();
  }
  for (auto &i : ans) {
    cout << i << "\n";
  }
}
void Test();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
