using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); Dictionary dict = new Dictionary(); for (var i = 0; i < n; ++i) { var no = Console.ReadLine(); var ms = Console.ReadLine().Trim().Split(' '); int m = int.Parse(ms[0]); int s = int.Parse(ms[1]); var tags = Console.ReadLine().Trim().Split(' '); foreach (var k in tags) { dict.TryAdd(k, 0); dict[k] += s; } } var arr = dict.Keys.Select(k => new { Key = k, Value = dict[k] }).ToArray(); Array.Sort(arr, (v0, v1) => { if (v0.Value != v1.Value) return -v0.Value.CompareTo(v1.Value); return v0.Key.CompareTo(v1.Key); }); int cnt = 0; foreach (var v in arr) { if (cnt >= 10) break; Console.WriteLine($"{v.Key} {v.Value}"); ++cnt; } } }