open System let ri () = stdin.ReadLine() |> int let ria () = stdin.ReadLine().Split() |> Array.map int type Sol() = member this.Solve() = let N = ri() let P = Array.zeroCreate N let A = Array.zeroCreate N for i in 0..N-1 do let d = ria() P.[i] <- d.[0] A.[i] <- d.[1..] let l = [ for i in 0..N-1 do for j in 0..P.[i]-1 do yield (A.[i].[j], i, j)] let result = l |> List.sortWith (fun (n, i, j) (m, i1, j1) -> (if j <> j1 then j.CompareTo(j1) else i.CompareTo(i1)) ) |> List.map (fun (n, i, j) -> n) String.Join(" ", result) |> printfn "%s" let mySol = new Sol() mySol.Solve()