def solve():
    N = int(input())
    K = [0]*N
    R = [0]*N
    L = [0]*N
    arr_back = []
    arr_front = []
    for i in range(N):
        K[i], L[i], R[i] = map(int,input().split(" "))
        if L[i] >= R[i] :
            arr_front.append( ( K[i], R[i]-L[i], i) )
        else :
            arr_back.append( ( N-K[i], L[i]-R[i], i) )
    
    arr_front.sort()
    arr_back.sort()

    ans = 0
    front = back = 0

    for k, _, j in arr_front:
        if front < k :
            ans += L[j]
            front += 1
        else :
            ans += R[j]
        # print(ans)

    for k, _, j in arr_back:
        if back < k :
            ans += R[j]
            back += 1
        else :
            ans += L[j]
        # print(ans)

    return ans 

T = int(input())
for _ in range(T) :
    print(solve())