fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let yuki = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.to_string() }) .collect::>(); let mut m = String::new(); std::io::stdin().read_line(&mut m).ok(); let m: usize = m.trim().parse().unwrap(); let coder = (0..m).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp = temp.trim(); temp.to_string() }) .collect::>(); let length = yuki.iter().map(|v| v.len()).sum::(); for i in 0..n { let mut y = yuki[i].clone().to_owned(); let mut c = String::new(); while y.len() < length || c.len() < length { if y.len() == c.len() { break; } if y.len() < c.len() { let start = c.chars().nth(y.len()).unwrap(); if let Some(x) = (0..n).filter(|&j| yuki[j].starts_with(start)).nth(0) { y.push_str(&yuki[x]); } else { break; } } else { let start = y.chars().nth(c.len()).unwrap(); if let Some(x) = (0..m).filter(|&j| coder[j].starts_with(start)).nth(0) { c.push_str(&coder[x]); } else { break; } } } if y.len() == c.len() && y.len() == length { println!("{}", y); return; } } println!("-1"); }