tag_management = {} photo_num = int(input()) for i in range(photo_num): input() tmp = input().split(" ") tag_num = int(tmp[0]) point = int(tmp[1]) tags = input().split(" ") for j in range(tag_num): if tags[j] not in tag_management: tag_management[tags[j]] = point else: tag_management[tags[j]] += point #print(tag_management) sorted_tag = sorted(tag_management.items(), key=lambda x: x[1]) count = 0 for i in range(len(sorted_tag)): count += 1 k,v = sorted_tag[i] print(str(k) + " " + str(v)) if count == 10: break """ for k, v in sorted(tag_management.items(), key=lambda x: x[1]): print(str(k) + " " + str(v)) """