n = int(input()) d = {} for _ in range(n): input() m, s = map(int, input().split()) l = input().split() for i in l: if not i in d: d[i] = s else: d[i] += s D = sorted(d.items(), key=lambda x: (-x[1], x[0])) for i in range(min(len(D), 10)): print(*D[i])