#include using namespace std; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vs = vector; using pll = pair; using vp = vector; template using V = vector; template using VV = vector >; #define rep(i, n) for(ll i = 0; i < (n); i++) #define repb(i, n) for(ll i = (n)-1; i >= 0; i--) #define repr(i, a, b) for(ll i = (a); i < (b); i++) #define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; } inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; } inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; } templateinline bool chmax(S &a, const T &b){ if(ainline bool chmin(S &a, const T &b){ if(b> n; vvll a(n); vll p(n); vll pt(n, 0); vll ans; rep(i, n){ cin >> p[i]; rep(j, p[i]){ ll a_; cin >> a_; a[i].emplace_back(a_); } } queue x; rep(i, n) x.emplace(i); while(!x.empty()){ ll idx = x.front(); x.pop(); if(pt[idx] < p[idx]){ ans.emplace_back(a[idx][pt[idx]]); } if(pt[idx] < p[idx]-1){ x.push(idx); pt[idx]++; } } rep(i, SZ(ans)){ cout << ans[i] << " \n"[i==SZ(ans)-1]; } return 0; }