import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap map = new HashMap<>(); for (int i = 0; i < n; i++) { sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); for (int j = 0; j < m; j++) { String s = sc.next(); if (map.containsKey(s)) { map.put(s, map.get(s) + p); } else { map.put(s, p); } } } PriorityQueue tags = new PriorityQueue<>(); for (Map.Entry entry : map.entrySet()) { tags.add(new Tag(entry.getKey(), entry.getValue())); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10 && tags.size() > 0; i++) { sb.append(tags.poll()).append("\n"); } System.out.print(sb); } static class Tag implements Comparable { String name; int value; public Tag(String name, int value) { this.name = name; this.value = value; } public int compareTo(Tag another) { if (value == another.value) { return name.compareTo(another.name); } else { return another.value - value; } } public String toString() { return name + " " + value; } } }