use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let mut q = std::collections::VecDeque::new(); for _ in 0..n { let p: usize = it.next().unwrap().parse().unwrap(); let mut a: Vec = (0..p).map(|_| it.next().unwrap().parse().unwrap()).collect(); a.sort(); a.reverse(); q.push_back(a); } let mut ans = String::new(); while let Some(mut a) = q.pop_front() { if let Some(v) = a.pop() { ans.push_str(&format!("{} ", v)); q.push_back(a); } } ans.pop(); println!("{}", ans); } fn main() { run(); }