#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, pair<T1, T2> P) {
  return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream& operator<<(ostream& s, vector<T> P) {
  for (long long i = 0; i < P.size(); ++i) {
    if (i > 0) {
      s << " ";
    }
    s << P[i];
  }
  return s;
}
template <class T>
ostream& operator<<(ostream& s, vector<vector<T>> P) {
  for (long long i = 0; i < P.size(); ++i) {
    s << endl << P[i];
  }
  return s << endl;
}
template <class T>
ostream& operator<<(ostream& s, set<T> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << *it << "> ";
  }
  return s << endl;
}
template <class T1, class T2>
ostream& operator<<(ostream& s, map<T1, T2> P) {
  for (__typeof__((P).begin()) it = (P).begin(); it != (P).end(); ++it) {
    s << "<" << it->first << "->" << it->second << "> ";
  }
  return s << endl;
}
template <class T>
void show(vector<T> v) {
  for (long long i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << "\n";
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> k(n), l(n), r(n);
  for (long long i = 0; i < n; i++) {
    cin >> k[i] >> l[i] >> r[i];
  }
  vector<pair<long long, pair<long long, long long>>> v(n);
  for (long long i = 0; i < n; i++) {
    v[i].first = k[i] * (l[i] - r[i]);
    v[i].second.first = -k[i];
    v[i].second.second = i;
  }
  sort((v).begin(), (v).end());
  reverse((v).begin(), (v).end());
  for (long long i = 0; i < n; i++) {
    v[i].second.first = -v[i].second.first;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i].second.first >= i + 1) {
      ans += l[v[i].second.second];
    } else {
      ans += r[v[i].second.second];
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
