import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); TagList tl = new TagList(); int n = sc.nextInt(); for(int i = 0; i < n; i++) { int no = sc.nextInt(); int m = sc.nextInt(); int s = sc.nextInt(); for(int j = 0; j < m; j++) { String tag = sc.next(); int index = tl.getIndex(tag); if(index== -1) { tl.getList().add(new Tag(tag,s)); } else { tl.getList().get(index).add(s); } } } tl.sort(); for(int i = 0; i < Math.min(10,tl.getList().size()); i++) { Tag tmp = tl.getList().get(i); System.out.println( tmp.getTag() + " " + tmp.getScore() ); } } } class TagList { List list = new ArrayList<>(); public int getIndex(String tag) { for(int i = 0; i < list.size(); i++) { if(tag.equals(this.list.get(i).getTag())) { return i; } } return -1; } public List getList() { return this.list; } public void sort() { Collections.sort(list, new TagStringComparator()); Collections.sort(list, new TagScoreComparator()); } } class Tag { public String tag; public int score; public Tag(String tag, int score) { this.tag = tag; this.score = score; } public String getTag() { return this.tag; } public int getScore() { return this.score; } public void add(int add) { this.score += add; } } class TagStringComparator implements Comparator { public int compare(Tag t1, Tag t2){ return t1.getTag().compareTo(t2.getTag()); } } class TagScoreComparator implements Comparator { public int compare(Tag t1, Tag t2){ return t2.getScore() - t1.getScore(); } }