import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
    n = int(input())
    score = 0
    line = []
    for _ in range(n):
        K, L, R = map(int, input().split())
        if K != n:
            score += min(L, R)
            if R < L:
                line.append((K, R-L))
            elif L < R:
                line.append((n, L-R))
            else:
                line.append((n, 0))
        else:
            line.append((n, -L))
    line.sort()
    for i in range(n):
        if i+1 <= line[i][0]:
            score += -line[i][1]
    print(score)
