class camel():
    def __init__(self, K, L, R):
        self.K = K
        self.R = R
        self.L = L
        self.diff = abs(L - R)


t = int(input())
for i in range(t):
    n = int(input())
    line = []
    for j in range(n):
        k, l, r = map(int, input().split())
        temp = camel(k, l, r)
        line.append(temp)
    line.sort(key=lambda x: x.diff, reverse=True)
    taken = set()
    small = 0
    ans = 0
    large = n-1
    for c in line:
        if c.R > c.L:
            if c.K <= large:
                temp = c.K
                temp1 = temp
                while taken.__contains__(temp):
                    temp += 1
                taken.add(temp)
                if temp == large:
                    while taken.__contains__(temp1):
                        temp1 -= 1
                    large = temp1
                ans += c.R
            else:
                ans += c.L
        elif c.L > c.R:
            if c.K > small:
                temp = c.K
                temp1 = temp
                while taken.__contains__(temp):
                    temp -= 1
                taken.add(temp)
                if temp == small:
                    while taken.__contains__(temp1):
                        temp1 += 1
                    small = temp1
                ans += c.L
            else:
                ans += c.R
        else:
            ans += c.L
    print(ans)
