import sys
input = sys.stdin.readline

T = int(input())

def solve():
    N = int(input())
    KLR = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2]-x[1])
    line = [-1]*N
    ans = 0
    for k, l, r in KLR:
        if l < r:
            break
        flg = False
        for i in range(k-1, -1, -1):
            if line[i] == -1:
                line[i] = 1
                flg = True
                break
        if flg:
            ans += l
        else:
            ans += r
    line = [-1] * N
    for k, l, r in KLR[::-1]:
        if l >= r:
            break
        flg = False
        for i in range(k, N):
            if line[i] == -1:
                line[i] = 1
                flg = True
                break
        if flg:
            ans += r
        else:
            ans += l
    print(ans)


for _ in range(T):
    solve()
