import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.next()); ArrayDeque[] queue = new ArrayDeque[n]; for(int i = 0; i < n; i++) { queue[i] = new ArrayDeque(); int rep = Integer.parseInt(sc.next()); for(int j = 0; j < rep; j++) { queue[i].add(Integer.parseInt(sc.next())); } } Queue ans = new ArrayDeque<>(); boolean flag; while(true) { flag = true; for(int i = 0; i < n; i++) { if(queue[i].size() == 0) continue; ans.add(queue[i].poll()); flag = false; } if(flag) break; } StringBuilder sb = new StringBuilder(); int rep = ans.size(); for(int i = 0; i < rep; i++) { sb.append(ans.poll()); sb.append(" "); } System.out.println(sb.toString().trim()); } }