#include <bits/stdc++.h>
using namespace std;
const int nsz = 2e3;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int ts, n;
namespace subtask1 {
long long dp[nsz + 5][nsz + 5], ans;
struct sheep {
  int k, w1, w2;
  sheep() {}
  sheep(int k, int w1, int w2) { this->k = k, this->w1 = w1, this->w2 = w2; }
  bool inline operator<(const sheep &wtm) const { return k < wtm.k; }
};
sheep dat[nsz + 5];
void inline solve() {
  ans = -inf;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int k, w1, w2;
    scanf("%d%d%d", &k, &w1, &w2);
    dat[i] = sheep(k, w1, w2);
  }
  sort(dat + 1, dat + n + 1);
  int o = 0, x = 1;
  for (int i = 0; i <= n; ++i) dp[o][i] = dp[x][i] = -inf;
  dp[o][0] = 0;
  for (int i = 1; i <= n; ++i) {
    int k = dat[i].k, w1 = dat[i].w1, w2 = dat[i].w2;
    for (int j = 0; j <= i; ++j) {
      int p1 = j, p2 = n - (i - j - 1);
      dp[x][j] = max(j ? dp[o][j - 1] + (p1 <= k ? w1 : w2) : -inf,
                     dp[o][j] + (p2 <= k ? w1 : w2));
    }
    swap(o, x);
    for (int j = 0; j <= i + 1; ++j) dp[x][j] = -inf;
  }
  for (int j = 0; j <= n; ++j) {
    ans = max(ans, dp[o][j]);
  }
  printf("%lld\n", ans);
}
};  // namespace subtask1
int main() {
  scanf("%d", &ts);
  for (int cs = 1; cs <= ts; ++cs) {
    subtask1::solve();
  }
  return 0;
}
