from collections import defaultdict

for _ in range(int(input())):
    n = int(input())
    arr = [input().split(',') for i in range(n)]
    di = defaultdict(set)
    ss = set()
    for (l, p, v) in arr:
        if v == 'OK':
            di[l] |= {p}
        ss.add(l)
    va = list(map(len, di.values()))
    if len(va) == 0:
        print(len(ss))
    else:
        print(va.count(max(va)))
