using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary(); var n = int.Parse(Console.ReadLine().Trim()); for (int i = 0; i < n; i++) getDic(d); foreach (var x in d.OrderByDescending(x => x.Value).ThenBy(x => x.Key).Take(Math.Min(10,d.Count()))) Console.WriteLine("{0} {1}", x.Key, x.Value); } public static void getDic(Dictionary d) { Console.ReadLine().Trim(); string[] line = Console.ReadLine().Trim().Split(' '); var m = int.Parse(line[0]); var s = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); for (int i = 0; i < m; i++) { var t = line[i]; if (d.ContainsKey(t)) d[t] += s; else d[t] = s; } } }