open System open System.Collections.Generic open System.Linq let read() = Console.ReadLine() let Int () = read() |> int let Ints() = read().Split() |> Array.map(int) let Int2() = let t = Ints() t.[0],t.[1] let dict = Dictionary() let N = Int() for i in 1..N do let No = Int() let M,S = Int2() let tags = read().Split() for t in tags do if not <| dict.ContainsKey t then dict.[t] <- S else dict.[t] <- dict.[t] + S dict.OrderByDescending(fun kp -> kp.Value).ThenBy(fun kp -> kp.Key).Take(10) |> Seq.iter (fun kp -> printfn "%s %i" kp.Key kp.Value)