from collections import defaultdict from operator import itemgetter N = int(input()) tags = defaultdict(int) for _ in range(N): _ = int(input()) m, s = map(int, input().split()) for t in input().split(): tags[t] += s print( "\n".join( [" ".join(map(str, x)) for x in sorted(tags.items(), key=lambda x: (-x[1], x[0]))][:10] ) )