import sys
t = int(input())
for _ in range(t):
    n = int(input())
    C = []
    ans = -1
    for i in range(n):
        a,b,c = map(int,sys.stdin.readline().split())
        C.append((a,b,c,))
    for i in range(1,2*n+1):
        for j in range(i+1,2*n+1):
            for k in range(j+1,2*n+1):
                s = 0
                p = [i,j,k]
                for a,b,c in C:
                    if a in p and b in p:s+=c
                if s > ans:ans=s
    for i in range(1,2*n +1):
        s = 0
        for a,b,c in C:
            if a == i or b == i:
                s+=c
        if s > ans:ans = s
    print(ans)


    
    
            
    