import sys
from collections import deque


def main():
    T = int(sys.stdin.readline().rstrip())
    for t in range(T):
        N = int(sys.stdin.readline().rstrip())
        C = []
        pnt = 0

        tmp_pnt = 0

        LC = []
        RC = []
        i = 0
        for n in range(N):
            k, l, r = map(int, sys.stdin.readline().rstrip().split())

            tmp_pnt += max(l,r)

            # 左寄せと右寄せに分ける
            if l > r:
                LC.append((k, r - l))  # 加点を増やす／正負反転して登録
                pnt += min(l,r)
            else:
                RC.append((N - k, l - r))  # 減点を減らす
                pnt += min(l,r)
            # print(i, pnt)

        # print("基本点", pnt)
        # print("最大点", tmp_pnt)

        LC.sort()
        RC.sort()

        # print(LC)
        # print(RC)

        LC = deque(LC)
        RC = deque(RC)

        S = 0  #
        tmp_pnt = 0
        for j in range(1, N+1):
            while LC:
                # 位置がjのものを取り出す
                if LC[0][0] == j:
                    # print(LC[0])
                    if S < j:
                        # print("Count")
                        pnt += -1 * LC[0][1]
                        tmp_pnt += -1 * LC[0][1]
                        S += 1
                    else:
                        # print("No Count")
                        pass
                    LC.popleft()
                else:
                    break

        # print("LC加点", tmp_pnt)

        S = 0  #
        tmp_pnt = 0

        # print(RC)

        for j in range(N):
            while RC:
                # 位置がjのものを取り出す
                if RC[0][0] == j:
                    # print(RC[0])
                    if S < j:
                        # print("Count")
                        pnt += -1 * RC[0][1]
                        tmp_pnt += -1 * RC[0][1]
                        S += 1
                    else:
                        # print("No Count")
                        pass
                    RC.popleft()
                else:
                    break

        # print("RC加点", tmp_pnt)
        print(pnt)


main()
