import java.io.*; import java.util.*; import java.util.Map.*; public class Main_yukicoder628 { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); Map hm = new HashMap<>(); for (int i = 0; i < n; i++) { @SuppressWarnings("unused") int no = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); for (int j = 0; j < m; j++) { String tag = sc.next(); if (hm.containsKey(tag)) { hm.put(tag, hm.get(tag) + s); } else { hm.put(tag, s); } } } List ans = new ArrayList<>(); for (Entry e : hm.entrySet()) { ans.add(new Pair(e.getKey(), e.getValue())); } Collections.sort(ans); for (int i = 0; i < 10; i++) { Pair e = ans.get(i); pr.printf("%s %d\n", e.a, e.b); } } private static class Pair implements Comparable { String a; int b; Pair(String a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { if (b == o.b) { return a.compareTo(o.a); } return Integer.compare(o.b, b); } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }