import java.util.HashMap; import java.util.Scanner; import java.util.Set; public class Tag { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int []No = new int[N]; int []S = new int[N]; //String str[][] = new String[N][]; HashMap> strD2 = new HashMap>(); for(int i = 0; i < N; i++) { No[i] = scanner.nextInt(); int M = scanner.nextInt(); S[i] = scanner.nextInt(); HashMap strD1 = new HashMap(); for(int j = 0; j < M; j++) { String s = scanner.next(); strD1.put(j, s); } strD2.put(i, strD1); } scanner.close(); HashMap pointHM = new HashMap(); pointHM.put(strD2.get(0).get(0), 0); int k; String key; for(int i = 0; i < N; i++) { k = strD2.get(i).size(); for(int j = 0; j < k; j++) { key = strD2.get(i).get(j); if(pointHM.containsKey(key)) { int s = pointHM.get(key); pointHM.put(key, s + S[i]); }else { pointHM.put(key, S[i]); } } } Set pointSet = pointHM.keySet(); String s = pointSet.toString().substring(1, pointSet.toString().length() - 1); String[] arrayKey = s.split("[\\s]*,[\\s]*"); int keyLen = arrayKey.length; int[]point = new int[keyLen]; for(int i = 0; i < keyLen; i++) { point[i] = pointHM.get(arrayKey[i]); } int v; int j; String temp; for(int i = 1; i < keyLen; i++) { v = point[i]; temp = arrayKey[i]; j = i - 1; while( j >= 0 && arrayKey[j].compareTo(temp) > 0) { arrayKey[j + 1] = arrayKey[j]; point[j + 1] = point[j]; j--; } arrayKey[j + 1] = temp; point[j + 1] = v; } for(int i = 1; i < keyLen; i++) { v = point[i]; temp = arrayKey[i]; j = i - 1; while( j >= 0 && point[j] < v) { arrayKey[j + 1] = arrayKey[j]; point[j + 1] = point[j]; j--; } arrayKey[j + 1] = temp; point[j + 1] = v; } if(keyLen > 10) { for(int i = 0; i < 10; i++) { System.out.println(arrayKey[i] + " " + point[i]); } }else { for(int i = 0; i < keyLen; i++) { System.out.println(arrayKey[i] + " " + point[i]); } } } }