N = int(input()) tags = {} for i in range(N): No = int(input()) M, S = map(int, input().split()) n_tags = input().split() for n_tag in n_tags: if n_tag not in tags: tags[n_tag] = S else: tags[n_tag] += S for key, value in sorted(sorted(tags.items()), key=lambda x: x[1], reverse=True)[:10]: print(key, value)