for i in range(int(input())):
    n = int(input())
    a, b, c = [], [], []
    for i in range(n):
        a1, b1, c1 = map(int, input().split())
        a.append(a1)
        b.append(b1)
        c.append(c1)
    ans = 0
    count = 0
    for i in range(2 * n):
        for j in range(2 * n):
            for o in  range(2 * n):
                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
    print(ans)
