using System; using System.Collections.Generic; using System.Linq; namespace y { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var d = new SortedDictionary(); for (int i = 0; i < n; i++) { Console.ReadLine(); //No string[] ss = Console.ReadLine().Split(); int m = int.Parse(ss[0]); int s = int.Parse(ss[1]); string[] tags = Console.ReadLine().Split(); foreach (var tag in tags) { if (d.ContainsKey(tag)) { d[tag] += s; } else { d.Add(tag, s); } } } int cnt = 0; var ans = d.OrderByDescending((x) => x.Value); foreach (var item in ans) { Console.WriteLine(item.Key + " " + item.Value.ToString()); cnt++; if (cnt == 10) break; } } } }