#include #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define range(a) a.begin(), a.end() using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector> Q(N); rep(i, N) { int m; cin >> m; rep(_, m) { int x; cin >> x; Q[i].push(x); } } vector ans; while (true) { bool upd = false; rep(i, N) { if (!Q[i].empty()) { ans.push_back(Q[i].front()); Q[i].pop(); upd = true; } } if (!upd) break; } for (int x : ans) cout << x << ' '; cout << endl; }