#include using namespace std; int main() { int N; cin >> N; vector> A( N ); for( int i = 0; i < N; i++ ) { int P; cin >> P; for( int j = 0; j < P; j++ ) { int a; cin >> a; A[i].push( a ); } } vector ans; int flag = 1; while( flag ) { flag = 0; for( int i = 0; i < N; i++ ) { if( A[i].empty() ) continue; int a = A[i].front(); A[i].pop(); ans.push_back( a ); flag = 1; } } for( int i = 0; i < ans.size(); i++ ) { if( i ) cout << " "; cout << ans[i]; } cout << endl; }