#include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(int i=0; i<(n); ++i) #define rep2(i, s, n) for(int i=s; i<(n); ++i) #define sz(x) int(x.size()) typedef long long ll; using namespace std; /*******-c++14 don't include-*******/ template T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); } template T lcm(T a, T b){return a*b/gcd(a,b); } /*******---------------------*******/ static const int INTINF = (2147483647); static const ll LLINF = (1ll<<32); static const int MAX = 1001; int main(int argc, const char * argv[]) { // input from txt ///////// //write// ///////// int n; queue q[MAX]; cin >> n; rep(i, n){ int p; cin >> p; rep(j, p){ int a; cin >> a; q[i].push(a); } } bool ok = true; queue res; while(ok){ ok = false; rep(i, n) { if(!q[i].empty()) { int f = q[i].front(); q[i].pop(); res.push(f); ok = true; } } } int v = res.size(); rep(i,v){ if(i)cout << " "; cout << res.front(); res.pop(); } cout << endl; return 0; }