n = int(input()) from collections import defaultdict d = defaultdict(int) for _ in range(n): input() m,s = map(int,input().split()) for t in input().split(): d[t] += s lst = [(-v,k) for k,v in d.items()] lst.sort() for v,k in lst[:10]: print(k,-v)