#include <bits/stdc++.h>
template <class T>
void rd(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
using namespace std;
const int N = 2e5 + 10;
int T, n;
struct ghb {
  int k, l, r;
  void read() {
    rd(k);
    rd(l);
    rd(r);
  }
} a[N];
int main() {
  rd(T);
  while (T--) {
    int mx = 0;
    long long ans = 0;
    rd(n);
    for (int i = 1; i <= n; i++) a[i].read(), mx = max(mx, a[i].k);
    for (int i = 1; i <= n; i++)
      if (a[i].k == mx)
        ans += a[i].l;
      else
        ans += max(a[i].l, a[i].r);
    printf("%lld\n", ans);
  }
  return 0;
}
