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

    for i in range(len(rear)):
        if rear[i][0] <= n-i:
            score += rear[i][1]

    print(score)
