#include <bits/stdc++.h>
using namespace std;
class minCostFlow {
  struct edge {
    long long to, cap, cost, rev;
  };
  long long V;
  vector<vector<edge> > G;
  vector<long long> dist;
  vector<long long> prevv;
  vector<long long> preve;

 public:
  minCostFlow(long long n) : G(n), dist(n), prevv(n), preve(n), V(n) {}
  void addEdge(long long from, long long to, long long cap, long long cost) {
    G[from].push_back((edge){to, cap, cost, (long long)G[to].size()});
    G[to].push_back((edge){from, 0, -cost, (long long)G[from].size() - 1});
  }
  long long solve(long long s, long long t, long long f) {
    long long ret = 0;
    while (f > 0) {
      fill(dist.begin(), dist.end(), 1000000000000000000LL);
      dist[s] = 0;
      bool update = true;
      while (update) {
        update = false;
        for (long long v = 0; v < V; v++) {
          if (dist[v] == 1000000000000000000LL) continue;
          for (long long i = 0; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
              dist[e.to] = dist[v] + e.cost;
              prevv[e.to] = v;
              preve[e.to] = i;
              update = true;
            }
          }
        }
      }
      if (dist[t] == 1000000000000000000LL) {
        return 1000000000000000000LL;
      }
      long long d = f;
      for (long long v = t; v != s; v = prevv[v]) {
        d = min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      ret += d * dist[t];
      for (long long v = t; v != s; v = prevv[v]) {
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return ret;
  }
};
void solve() {
  long long n;
  cin >> n;
  long long m = n + 2;
  minCostFlow mcf(4 * m + 10);
  for (long long(i) = (0); (i) < (n); ++i) {
    mcf.addEdge(m + i, 3 * m + i, 1, 0);
    mcf.addEdge(2 * m + i, 3 * m + i, 1, 0);
    mcf.addEdge(3 * m + i, 4 * m + 1, 1, 0);
    if (i == n - 1) continue;
    mcf.addEdge(m + i, m + i + 1, 1000000000, 0);
    mcf.addEdge(2 * m + i + 1, 2 * m + i, 1000000000, 0);
  }
  for (long long(i) = (0); (i) < (n); ++i) {
    long long k, l, r;
    cin >> k >> l >> r;
    mcf.addEdge(4 * m, i, 1, 0);
    mcf.addEdge(i, m + k, 1, -r);
    mcf.addEdge(i, 2 * m + k - 1, 1, -l);
  }
  cout << -mcf.solve(4 * m, 4 * m + 1, n) << endl;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  for (long long(i) = (0); (i) < (t); ++i) solve();
  return 0;
}
