def max():
    S=[]
    N=int(input())
    cases=[list(map(int,input().split())) for i in range(N)]
    Li=[]
    Ri=[]
    for case in cases:
        if case[1]>=case[2]:
            Li.append(case)
        else:
            Ri.append(case)
            
    for j in range(1,N+1):
        for l in Li:
            if l[0]==j:
                S.append(l)
            while len(S)>j:
                min=S[0][1]-S[0][2]
                k=0
                for i in range(len(S)):
                    if S[i][1]-S[i][2]<min:
                        k=i
                        min=S[i][1]-S[i][2]
                del S[k]
    le=len(S)            
    for j in range(1,N+1):
        for R in Ri:
            if R[0]==j:
                S.append(R)
            while len(S)>j+le:
                min=S[0][2]-S[0][1]
                k=0
                for i in range(len(S)):
                    if S[i][2]-S[i][1]<min:
                        k=i
                        min=S[i][2]-S[i][1]
                del S[k]
    sum=0
    for j in range(len(S)):
        if S[j][0]>=j+1:
            sum+=S[j][1]
            
        else:
            sum+=S[j][2]
            
    print(sum)

T=int(input())
for i in range(T):
    max()