T = int(input())
ans = []
for t in range(T):
    tmpans =0
    N = int(input())
    KLR = [list(map(int,input().split())) for i in range(N)]
    goL =[]#Lに行きたい人
    goR =[]
    for i in range(N):
        if KLR[i][1] > KLR[i][2]:
            goL.append(KLR[i])
        else:
            goR.append(KLR[i])

    is_closed=[0]*(N+1)#i番目があいているか
    goL.sort(key=lambda x:x[1]-x[2])
    goR.sort(key=lambda x:x[2]-x[1])


    for i in goL:
        j = i[0]#以内にはいりたい
        while j > 0:
            if is_closed[j]==0:
                tmpans += i[1]
                is_closed[j]=1
                break
            j-=1
        if j==0:
            tmpans+=i[2]

    is_closed = [0]*(N+1)
    for i in goR:
        j = i[0]+1#以内にはいりたい
        while j < N+1:
            if is_closed[j]==0:
                tmpans += i[2]
                is_closed[j]=1
                break
            j+=1

        if j==N+1:
            tmpans+=i[1]
    ans.append(tmpans)

for i in range(len(ans)):
    print(ans[i])

