n=int(input()) d={} for _ in range(n): input() m,s=map(int,input().split()) for i in list(input().split()): if i in d: d[i]+=s else: d[i]=s k=sorted([(-b,a) for a,b in zip(d.keys(),d.values())]) for i in range(min(10,len(k))): a,b=k[i] print(b,-a)