using System; using System.Collections.Generic; using System.Linq; namespace _628 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Dictionary tag = new Dictionary(); for (int i = 0; i < n; i++) { Console.ReadLine(); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); string[] s = Console.ReadLine().Split(); for (int j = 0; j < x[0]; j++) { if (!tag.ContainsKey(s[j])) tag[s[j]] = 0; tag[s[j]] += x[1]; } } int count = 0; for (int i = n * 10 + 10; i >= 0; i--) { List list = new List(); foreach (var item in tag) { if (item.Value == i) { list.Add(item.Key); } } string[] s = list.ToArray(); Array.Sort(s); for (int j = 0; j < s.Count(); j++) { Console.WriteLine(s[j] + " " + i); count++; if (count == 10) break; } if (count == 10) break; } } } }