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]; } } var sorted = tag.OrderBy((x) => x.Key); int count = 0; for (int i = n * 10 + 10; i >= 0; i--) { foreach (var item in sorted) { if (item.Value == i) { count++; Console.WriteLine(item.Key + " " + item.Value); } if (count == 10) break; } if (count == 10) break; } } } }