let n = stdin.ReadLine () |> int let mutable scoreMap = Map.empty for _ in 0..n-1 do let no = stdin.ReadLine () |> int let [|m; s|] = stdin.ReadLine().Split " " |> Array.map int let tags = stdin.ReadLine().Split " " for i in tags do scoreMap <- scoreMap.Add (i, s + (if scoreMap.ContainsKey i then scoreMap.[i] else 0)) scoreMap |> Map.toArray |> Array.sortWith (fun (tag1, value1) (tag2, value2) -> if value1 = value2 then compare tag1 tag2 else -(compare value1 value2)) |> (fun arr -> if arr.Length < 10 then arr else Array.take 10 arr) |> Array.iter (fun (tag, value) -> printfn "%s %d" tag value)