T = int(input())
mapping = [[-1, -1] for _ in range(2*100000)]
ans_l = [0 for _ in range(T)]
for t in range(T):
    ans = 0
    N = int(input())
    for i in range(N):
        K, L, R = map(int, input().split())
        if mapping[K-1][1] != t:
            ans += max(L, R)
            mapping[K-1][0] = max(L, R)
            mapping[K-1][1] = t
        elif mapping[K-1][0] > L or mapping[K-1][0] > R:
            ans += max(L, R)
    ans_l[t-1] = ans
for a in ans_l:
    print(a)