def priority(klr):
    return abs(klr[1]-klr[2])

def solve():
    N = int(input())
    KLR = []
    for _ in range(N):
        klr = list(map(int, input().split()))
        klr[0] -= 1 # convert to 0-basedi index to avoid confusion                                                                                                                                          
        KLR.append(klr)
    ans = 0
    KLR_L = []
    KLR_R = []
    for klr in KLR:
        if klr[1] > klr[2]:
            KLR_L.append(klr)
        elif klr[1] < klr[2]:
            KLR_R.append(klr)
        else:
            ans += klr[1]
    KLR_L.sort(key=lambda klr: -priority(klr))
    KLR_L.sort(key=lambda klr: klr[0])
    KLR_R.sort(key=lambda klr: -priority(klr))
    KLR_R.sort(key=lambda klr: -klr[0])
    lp = 0
    rp = N - 1
    filled = [False] * N
    il = 0
    ir = 0
    while il < len(KLR_L) or ir < len(KLR_R):
        if il < len(KLR_L) and \
           (ir == len(KLR_R) or priority(KLR_L[il]) > priority(KLR_R[ir])):
            klr = KLR_L[il]
            if klr[0] >= lp and filled[lp] == False:
                filled[lp] = True
                lp+=1
                ans += max(klr[1], klr[2])
            else:
                ans += min(klr[1], klr[2])
            il += 1
        else:
            klr = KLR_R[ir]
            if klr[0] < rp and filled[rp] == False:
                filled[rp] = True
                rp -= 1
                ans += max(klr[1], klr[2])
            else:
                ans += min(klr[1], klr[2])
            ir += 1
    print(ans)


T = int(input())

for _ in range(T):
    solve()