import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

t = ni()

for _ in range(t):
    n = ni()
    a = []
    for i in range(n):
        k,l,r = na()
        a.append((abs(l-r),k,l,r))
    a.sort(reverse=True)
    g = [0]*n
    ans = 0
    for _, k,l,r in a:
        if l == r:
            ans+=l
            continue
        elif l > r:
            kk = k-1
            while kk >= 0:
                if g[kk] == 0:
                    g[kk] = l
                    break
                kk -= 1
            else:
                ans += r
        else:
            kk = k
            while kk < n:
                if g[kk] == 0:
                    g[kk] = r
                    break
                kk += 1
            else:
                ans += l
    ans += sum(g)
    print(ans)