n=int(input()) from collections import defaultdict d=defaultdict(int) for i in range(n): a=input() m,s=map(int,input().split()) for t in input().split(): d[t]+=s l=[] for t in d: l.append((-d[t],t)) l.sort() for p,t in l[:10]: p=-p print(t,p)