import sys
sys.setrecursionlimit(10 ** 8)

def input(): return sys.stdin.readline().strip()
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    T = Z()
    ans = []
    for _ in range(T):
        N = Z()
        camel = []
        for _ in range(N):
            K, L, R = ZZ()
            camel.append([K, L, R])
        camel.sort()
        isseen = [False] * N
        order = 1
        cc = 0
        for i in range(N):
            k, l, r = camel[i]
            if l > r:
                isseen[i] = True
                if order <= k: cc += l
                else: cc += r
                order += 1
            else: continue
        for i in range(N):
            if isseen[i]: continue
            k, l, r = camel[i]
            isseen[i] = True
            if order <= k: cc += l
            else: cc += r
            order += 1
        ans.append(cc)

    for a in ans:
        print(a)

    return

if __name__ == '__main__':
    main()
