#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector> a(n); rep(i, n) { int p; cin >> p; rep(_, p) { int x; cin >> x; a[i].push(x); } } queue ans; queue q; rep(i, n) if (!a[i].empty()) q.push(i); while (!q.empty()) { int idx = q.front(); q.pop(); int x = a[idx].front(); a[idx].pop(); ans.push(x); if (!a[idx].empty()) q.push(idx); } while (!ans.empty()) { cout << ans.front() << ' '; ans.pop(); } cout << endl; return 0; }