import heapq

t = int(input())
for i in range(t):
    n = int(input())
    a1 = []
    a2 = []
    ans = 0
    for j in range(n):
        k, l, r = map(int, input().split())
        if l > r:
            a1.append([l - r, k])
            ans += l
        elif l < r:
            a2.append([r - l, n - k])
            ans += r
        else:
            ans += l
    a1.sort(key = lambda x: x[1])
    a2.sort(key = lambda x: x[1])
    num = 1
    num2 = 0
    num3 = 0
    queue = []
    heapq.heapify(queue)
    while num <= n:
        if num2 == len(a1):
            break
        else:
            while a1[num2][1] == num:
                heapq.heappush(queue, a1[num2])
                num2 += 1
                num3 += 1
                if num2 == len(a1):
                    break
            while num3 > num:
                temp = heapq.heappop(queue)
                ans -= temp[0]
                num3 -= 1
            else:
                num += 1
    num = 0
    num2 = 0
    num3 = 0
    queue = []
    heapq.heapify(queue)
    while num <= n:
        if num2 == len(a2):
            break
        else:
            while a2[num2][1] == num:
                heapq.heappush(queue, a2[num2])
                num2 += 1
                num3 += 1
                if num2 == len(a2):
                    break
            while num3 > num:
                temp = heapq.heappop(queue)
                ans -= temp[0]
                num3 -= 1
            else:
                num += 1
    print(ans)