#include "bits/stdc++.h" using namespace std; void solve() { int n; cin >> n; vector> r; int res = 0; for (int i = 0; i < n; i++) { int p; cin >> p; res += p; queue q; while (p--) { int x; cin >> x; q.push(x); } r.push_back(q); } for (int cnt = 0; res; cnt++) { int i = cnt % n; if (r[i].empty()) { continue; } res--; cout << r[i].front() << ' '; r[i].pop(); } cout << endl; } int main() { solve(); return 0; }