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] * (2 * n)
    for i in range(n):
        ans[a[i] - 1] += c[i]
        ans[b[i] - 1] += c[i]
    print(max(ans))
