#include <bits/stdc++.h>
using namespace std;
const long long INFLL = LLONG_MAX;
const int INF = INT_MAX;
const long long MAXLL = 0x3f3f3f3f3f3f3f3f;
const int MAX = 0x3f3f3f3f;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T, class U>
void sort(vector<T>& v, U func) {
  sort(v.begin(), v.end(), func);
}
template <class T>
void rsort(vector<T>& v) {
  sort(v.rbegin(), v.rend());
}
template <class T>
int lb_index(vector<T>& v, T k) {
  return lower_bound(v.begin(), v.end(), k) - v.begin();
}
template <class T>
int ub_index(vector<T>& v, T k) {
  return upper_bound(v.begin(), v.end(), k) - v.begin();
}
template <class T>
bool is_sorted(vector<T>& v) {
  return is_sorted(v.begin(), v.end());
}
template <class T>
bool sorted(vector<T>& v) {
  return is_sorted(v);
}
struct flow {
  int n, s, t;
  const long long MAXVAL = 0x3f3f3f3f3f3f3f3f;
  bool flowed = 0;
  struct edge {
    int from, to;
    long long cap, cost;
    edge(int u, int v, long long c, long long w)
        : from(u), to(v), cap(c), cost(w) {}
    edge(int u, int v, long long c) : from(u), to(v), cap(c) { cost = 0; }
  };
  vector<edge> e;
  vector<vector<int> > adj;
  vector<long long> dist;
  vector<int> par;
  vector<bool> inq;
  long long finalmaxflow, finalcost;
  void spfa() {
    fill(dist.begin(), dist.end(), MAXVAL);
    fill(inq.begin(), inq.end(), 0);
    fill(par.begin(), par.end(), 0);
    queue<int> q;
    dist[s] = 0;
    q.emplace(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      inq[u] = 0;
      for (auto i : adj[u]) {
        if (e[i].cap <= 0) continue;
        int v = e[i].to;
        long long l = e[i].cost;
        if (dist[u] + l < dist[v]) {
          dist[v] = dist[u] + l;
          par[v] = i;
          if (!inq[v]) q.emplace(v), inq[v] = 1;
        }
      }
    }
  }
  long long augcost() {
    long long curflow = MAXVAL;
    for (int u = t; u != s; u = e[par[u]].from) {
      curflow = min(curflow, e[par[u]].cap);
    }
    for (int u = t; u != s; u = e[par[u]].from) {
      e[par[u]].cap -= curflow;
      e[par[u] ^ 1].cap += curflow;
    }
    return curflow;
  }
  flow(int n, int s, int t)
      : n(n), s(s), t(t), dist(n), inq(n), par(n), adj(n) {}
  void addedge(int u, int v, long long c, long long w) {
    adj[u].emplace_back(e.size());
    e.emplace_back(u, v, c, w);
    adj[v].emplace_back(e.size());
    e.emplace_back(v, u, 0, -w);
  }
  void addedge(int u, int v, long long c) {
    adj[u].emplace_back(e.size());
    e.emplace_back(u, v, c);
    adj[v].emplace_back(e.size());
    e.emplace_back(v, u, 0);
  }
  void setflow(long long k) {
    int ns = n++;
    adj.resize(n);
    dist.resize(n);
    inq.resize(n);
    par.resize(n);
    addedge(ns, s, k, 0);
    s = ns;
  }
  void flowit() {
    long long maxflow = 0, cost = 0;
    for (;;) {
      spfa();
      if (dist[t] == MAXVAL) break;
      long long f = augcost();
      maxflow += f;
      cost += dist[t] * f;
    }
    finalmaxflow = maxflow;
    finalcost = cost;
    flowed = 1;
  }
  long long getflow() {
    if (!flowed) flowit();
    return finalmaxflow;
  }
  long long getcost() {
    if (!flowed) flowit();
    return finalcost;
  }
};
void solve() {
  int n;
  cin >> n;
  flow f(n + n + 2, n + n, n + n + 1);
  for (int i = 0; i < n; i++) {
    f.addedge(n + n, i, 1, 0);
    f.addedge(n + i, n + n + 1, 1, 0);
    long long k, l, r;
    cin >> k >> l >> r;
    for (int j = 0; j < k; j++) {
      f.addedge(i, n + j, 1, -l);
    }
    for (int j = k; j < n; j++) {
      f.addedge(i, n + j, 1, -r);
    }
  }
  cout << -f.getcost() << endl;
}
int main() {
  ios::sync_with_stdio(0);
  int numberofsubtestcases = 1;
  cin >> numberofsubtestcases;
  while (numberofsubtestcases--) {
    solve();
  }
}
