use std::{collections::HashMap, io::Read}; fn main() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let s: Vec<_> = s.lines().skip(1).collect(); let mut h = HashMap::new(); s.chunks(3).for_each(|s| { let n: Vec = s[1].split_whitespace().flat_map(str::parse).collect(); s[2].split_whitespace().for_each(|t| { *h.entry(t).or_insert(0) += n[1]; }); }); let mut a: Vec<_> = h.iter().map(|(k, v)| (-v, k)).collect(); a.sort(); (0..10.min(a.len())).for_each(|i| println!("{} {}", a[i].1, -a[i].0)); }