import sys
for i in range(int(sys.stdin.readline())):
    n = int(sys.stdin.readline())
    a, b, c = [], [], []
    for i in range(n):
        a1, b1, c1 = map(int, sys.stdin.readline().split())
        a.append(a1)
        b.append(b1)
        c.append(c1)
    ans = 0
    count = 0
    for i in range(1, 2 * n + 1):
        for j in range(i, 2 * n + 1):
            for o in  range(j, 2 * n + 1):
                if len(set([i, j, o])) != 3:
                    continue
                for k in range(n):
                    if a[k] in [i, j, o] and b[k] in [i, j, o]:
                        count += c[k]
                ans = max(ans, count)
                count = 0
    ans1 = [0] * (2 * n)
    for i in range(n):
        ans1[a[i] - 1] += c[i]
        ans1[b[i] - 1] += c[i]
    print(max(ans, max(ans1)))