import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.List; import java.util.Queue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int cnt = 0; List> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { Queue que = new ArrayDeque<>(); list.add(que); String[] sa = br.readLine().split(" "); if (Integer.parseInt(sa[0]) == 0) { cnt++; } for (int j = 1; j < sa.length; j++) { que.add(Integer.parseInt(sa[j])); } } br.close(); StringBuilder sb = new StringBuilder(); while (cnt < n) { for (int i = 0; i < n; i++) { Queue que = list.get(i); if (!que.isEmpty()) { sb.append(que.poll()).append(' '); if (que.isEmpty()) { cnt++; } } } } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } }