N = int(input().strip()) dic = {} for i in range(N): No = int(input().strip()) M, S = map(int, input().strip().split()) Tag = input().strip().split() print('No:{} M:{} S:{} Tag:{}'.format(No, M, S, Tag)) for j in Tag: try: dic[j] += S except: dic[j] = S dic = sorted(dic.items(), key = lambda x:x[0]) for i in sorted(dic, key = lambda x:x[1], reverse=True)[:10]: print('{} {}'.format(i[0], i[1]))