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 count = sc.nextInt(); int point = sc.nextInt(); for (int j = 0; j < count; j++) { String s = sc.next(); if (map.containsKey(s)) { map.put(s, map.get(s) + point); } else { map.put(s, point); } } } PriorityQueue queue = new PriorityQueue<>(); for (Map.Entry entry : map.entrySet()) { queue.add(new Tag(entry.getValue(), entry.getKey())); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10 && queue.size() > 0; i++) { sb.append(queue.poll()).append("\n"); } System.out.print(sb); } static class Tag implements Comparable{ int score; String word; public Tag (int score, String word) { this.score = score; this.word = word; } public int compareTo(Tag another) { if (score == another.score) { return word.compareTo(another.word); } else { return another.score - score; } } public String toString() { return word + " " + score; } } }