import sys,collections from operator import itemgetter sys.setrecursionlimit(10**7) def Is(): return [int(x) for x in sys.stdin.readline().split()] def Ss(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def S(): return input() n = I() d = collections.defaultdict(int) for i in range(n): no = I() m,s = Is() tags = Ss() for tag in tags: d[tag] += s ans = sorted(d.items(),key=itemgetter(0)) ans = sorted(ans,key=itemgetter(1),reverse=True)[:10] for e in ans: print(e[0],e[1])