use std::collections::HashMap; fn main() { let mut buf = String::new(); let mut input = { use std::io::Read; std::io::stdin().read_to_string(&mut buf).unwrap(); buf.split_whitespace() }; let n: usize = input.next().unwrap().parse().unwrap(); let m: usize = input.next().unwrap().parse().unwrap(); let mut s = vec![]; let mut a = vec![]; for _ in 0..n { let s_i: String = input.next().unwrap().parse().unwrap(); let a_i: usize = input.next().unwrap().parse().unwrap(); s.push(s_i); a.push(a_i); } let mut t = vec![]; let mut b = vec![]; for _ in 0..m { let t_j: String = input.next().unwrap().parse().unwrap(); let b_j: usize = input.next().unwrap().parse().unwrap(); t.push(t_j); b.push(b_j); } let mut rate_map = HashMap::new(); for i in 0..n { rate_map.insert(s[i].clone(), a[i]); } for j in 0..m { rate_map.insert(t[j].clone(), b[j]); } let mut rate_vec = rate_map.into_iter().collect::>(); rate_vec.sort_by(|(key1, _), (key2, _)| key1.cmp(&key2)); for (name, rate) in &rate_vec { println!("{} {}", name, rate); } }