import sys
input = sys.stdin.readline
from collections import *
sys.setrecursionlimit(2*10**5+100)

def dfs(i, l):
    if i==N:
        return 0
        
    K, L, R = KLR[i]
    res = 0
    if i+1<=K:
        res = max(res, dfs(i+1, l+1)+L)
    if i-l+1<=N-K:
        res = max(res, dfs(i+1, l)+R)
    return res

T = int(input())

for _ in range(T):
    N = int(input())
    KLR = [tuple(map(int, input().split())) for _ in range(N)]
    KLR.sort(key=lambda t: t[0])
    print(dfs(0, 0))