#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < int(n); i++) #define FOR(i,n,m) for(int i = int(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; int main() { int n; cin >> n; vector> a(n); vector ans; int empty = 0; REP(i, n) { int p; cin >> p; if (p == 0) empty++; REP(j, p) { int b; cin >> b; a[i].push(b); } } int now = -1; while (empty < n) { now = (now + 1) % n; if (a[now].empty()) continue; ans.push_back(a[now].front()); a[now].pop(); if (a[now].empty()) empty++; } REP(i, ans.size()) { cout << ans[i] << " "; } cout << endl; }