using System.Text; using System.Linq; using System.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var q = new Queue[n]; for (int i = 0; i < n; i++) q[i] = new Queue(); var tc = 0; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var m = int.Parse(line[0]); tc += m; for (int j = 0; j < m; j++) q[i].Enqueue(int.Parse(line[j + 1])); } getAns(n, q, tc); } static void getAns (int n, Queue[]q , int tc ) { var sb = new StringBuilder(); var p = 0; var count = 0; while (true) { if (q[p].Count() > 0) { sb.Append(q[p].Dequeue().ToString() + "\n"); count++; if (count == tc) break; } p++; if (p == n) p = 0; } Console.Write(sb); } }