import sys

def find_popular():
    boys_types = int(sys.stdin.readline())
    boys = []
    girls = [0] * 2 * boys_types
    boys_like_popular = []
    combs_girls = []
    combs = []
    differences = []
    boys_like_pops_number = 0

    for _ in range(boys_types):
        a, b, c = map(int, sys.stdin.readline().split())
        for __ in range(c):
            boys.append([a, b])


    for boy_type in boys:
        for girl in boy_type:
            girls[girl - 1] += 1

    popular = max(girls)
    return popular

tests = int(input())
tests_results = []

for _ in range(tests):
    tests_results.append(find_popular())

for result in tests_results:
    print(result)