import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        if x == 0:
            return 0

        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1

    def __repr__(self):
        return str(self._container)


def main():
    from operator import add, itemgetter

    t = int(readline())

    for _ in range(t):
        n = int(readline())
        res = 0
        tr1 = BinaryIndexTree(n)
        tr2 = BinaryIndexTree(n)
        mat = [[0] * 4 for __ in range(n)]
        for i in range(n):
            k, l, r = map(int, readline().split())
            mat[i][0] = k
            mat[i][1] = abs(l - r)
            mat[i][2] = l
            mat[i][3] = r
        mat.sort(key=itemgetter(1), reverse=True)

        for k, abs_val, l, r in mat:
            if l - r > 0:
                if tr1.sum(k) < k:
                    res += l
                    tr1.add(k, 1)
                else:
                    res += r
            else:
                if tr2.sum(n - k) < n - k:
                    res += r
                    tr2.add(n - k, 1)
                else:
                    res += l
        print(res)


if __name__ == '__main__':
    main()
