import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Scanner; import java.util.TreeSet; public class Main { public static class Pair implements Comparable { String tag; long score; public Pair(String tag, long score){ this.tag = tag; this.score = score; } @Override public int compareTo(Pair o) { if(Long.compare(o.score, this.score) != 0){ return Long.compare(o.score, this.score); }else{ return this.tag.compareTo(o.tag); } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); HashMap dict = new HashMap(); for(int i = 0; i < N; i++){ final int id = sc.nextInt(); final int M = sc.nextInt(); final int S = sc.nextInt(); for(int j = 0; j < M; j++){ final String tag = sc.next(); if(!dict.containsKey(tag)){ dict.put(tag, 0l); } dict.put(tag, dict.get(tag) + S); } } PriorityQueue queue = new PriorityQueue(); for(final Entry entry : dict.entrySet()){ queue.add(new Pair(entry.getKey(), entry.getValue())); } for(int i = 0; i < 10 && !queue.isEmpty(); i++){ final Pair pair = queue.poll(); System.out.println(pair.tag + " " + pair.score); } } }