N = int(input()) tag_score = dict() for _ in range(N): no = input() num, score = map(int, input().split()) tags = input().split() for tag in tags: if tag in tag_score: tag_score[tag] += score else: tag_score[tag] = score for i, (t, s) in enumerate(sorted(sorted(tag_score.items(), key=lambda x: x[0]), reverse=True, key=lambda x: x[1])): if i >= 10: break print(str(t) + ' ' + str(s))