def find_popular():
    boys_types = int(input())
    gals_types = 2 * boys_types
    boys = []
    girls = [0] * gals_types

    for _ in range(boys_types):
        a, b, c = map(int, input().split())
        boys.append([a, b] * c)

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

    return max(girls)

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

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

for result in tests_results:
    print(result)