#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, tree[maxn];
long long k[maxn], l[maxn], r[maxn], dp[maxn][2];
void add(int p, int x) {
  for (; p <= n; p += p & (-p)) tree[p] += x;
}
int ask(int p) {
  int res = 0;
  for (; p; p -= p & (-p)) res += tree[p];
  return res;
}
int binsearch(bool flag) {
  int l = 0, r = n, m;
  if (flag) {
    while (l + 1 < r) {
      m = (l + r) << 1;
      if (ask(l) == l)
        l = m;
      else
        r = m;
    }
    return l + 1;
  }
  while (l + 1 < r) {
    m = (l + r) << 1;
    if (ask(n) - ask(r) == n - r)
      r = m;
    else
      l = m;
  }
  return r - 1;
}
void dfs(int dep) {
  if (dep > n) return;
  if (ask(k[dep]) == k[dep]) {
    dp[dep][0] = max(dp[dep][0], max(dp[dep - 1][0], dp[dep - 1][1]) + r[dep]);
    dp[dep][1] = -1000000000000000000ll;
    add(binsearch(false), 1);
    dfs(dep + 1);
  } else if (ask(n) - ask(k[dep]) == n - k[dep]) {
    dp[dep][0] = -1000000000000000000ll;
    dp[dep][1] = max(dp[dep][1], max(dp[dep - 1][0], dp[dep - 1][1]) + l[dep]);
    add(binsearch(true), 1);
    dfs(dep + 1);
  } else {
    dp[dep][0] = max(dp[dep][0], max(dp[dep - 1][0], dp[dep - 1][1]) + r[dep]);
    int p = binsearch(true);
    add(p, 1);
    dfs(dep + 1);
    add(p, -1);
    dp[dep][1] = max(dp[dep][1], max(dp[dep - 1][0], dp[dep - 1][1]) + l[dep]);
    add(binsearch(false), 1);
    dfs(dep + 1);
  }
}
int main() {
  int t, i;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) scanf("%lld%lld%lld", k + i, l + i, r + i);
    for (i = 1; i <= n; i++) tree[i] = dp[i][0] = dp[i][1] = 0;
    dfs(1);
    printf("%lld\n", max(dp[n][0], dp[n][1]));
  }
  return 0;
}
