#include <cstdio>
#include <algorithm>
#include <utility>
#include <set>
#include <cstring>
#include <cstdlib>
#define MAX 1008
#define MOD		1000000007
#define HASH1	10007
#define HASH2	20011

int hash1_inv;
int hash2_inv;

using namespace std;


typedef long long ll;
typedef pair< int, int > pii;

int niz[MAX][MAX];
int hash1[MAX][MAX];
int hash2[MAX][MAX];
pii sorted[MAX*MAX];
int sort_pos[MAX][MAX];
int n, m[MAX];
int result[MAX*MAX];

struct cmp_fast {
	inline bool operator()( const pii &a, const pii &b ) const {
		return sort_pos[a.first][a.second] < sort_pos[b.first][b.second]
			|| sort_pos[a.first][a.second] == sort_pos[b.first][b.second] && a < b;
	}	
};

set < pii, cmp_fast > s;

int power( int x, int y ) {
	if ( y == 0 ) return 1;
	if ( y == 1 ) return x;
	if ( y & 1 ) return ((ll)power( x, y-1 ) * (ll)x) % MOD;
	int tmp = power( x, y / 2 );
	return ( (ll)tmp * tmp ) % MOD;
}

inline int hash1_query( int i, int a, int b ) {
	if ( a == 0 ) return hash1[i][b];
//	printf("%d %d  %d-%d  -> %d\n", a, b, hash[i][b], hash[i][a-1],  
//		(int)((( hash[i][b] - hash[i][a-1] ) * (ll)power( hash_inv, a )) % MOD) );
	return (( hash1[i][b] - hash1[i][a-1] ) * (ll)power( hash1_inv, a )) % MOD;
}
inline int hash2_query( int i, int a, int b ) {
	if ( a == 0 ) return hash2[i][b];
	return (( hash2[i][b] - hash2[i][a-1] ) * (ll)power( hash2_inv, a )) % MOD;
}

inline bool cmp( const pii &a, const pii &b ) {
/*	return lexicographical_compare(
		 niz[a.first] + a.second, niz[a.first] + m[a.first]
		,niz[b.first] + b.second, niz[b.first] + m[b.first] );//*/
		
	
	int tmp = min( m[a.first] - a.second, m[b.first] - b.second );
	int t = 0, k;
	int A, B;
	for ( k = 1; k <= tmp; k <<= 1 );
	
	while ( 1 ) {
		k /= 2;
		while ( t + k > tmp && k > 0 ) k /= 2;
		if ( k == 0 ) break;
		A = hash1_query( a.first, a.second + t + k-1, m[a.first] - 1 );
		B = hash1_query( b.first, b.second + t + k-1, m[b.first] - 1 );
//		printf("k=%d t=%d %d %d   %d %d\n", k, t, A, B, a.second + t + k-1, m[a.first] - 1);
		if ( A == B ) {
			A = hash2_query( a.first, a.second + t + k-1, m[a.first] - 1 );
			B = hash2_query( b.first, b.second + t + k-1, m[b.first] - 1 );
			if ( A == B ) t += k;
		}
	}	
	
//	printf(" t = %d\n", t );

	
	bool result;
	do {
		if ( niz[a.first][a.second + t] < niz[b.first][b.second + t] ) { result = 1; break; }
		if ( niz[a.first][a.second + t] > niz[b.first][b.second + t] ) { result = 0; break; }
		++t;
		if ( t >= m[a.first] ) { result = 1; break; }
		if ( t >= m[b.first] ) { result = 0; break; }
	} while ( 1 );
	
//	printf("{%d %d} {%d %d}  %d  %d\n", a.first, a.second, b.first, b.second, result, t);
	return result;
}


int main(void) {
	int i, j, k, r;
	scanf("%d", &n);
	for ( i = 0; i < n; ++i ) {
		scanf("%d", &m[i]);
		for ( j = 0; j < m[i]; ++j ) {
			scanf("%d", &niz[i][j]);
			if ( j > 0 ) {
				hash1[i][j] = ((ll)hash1[i][j-1] * HASH1 + niz[i][j]) % MOD;
				hash2[i][j] = ((ll)hash2[i][j-1] * HASH2 + niz[i][j]) % MOD;
			} else {
				hash1[i][0] = niz[i][0] % MOD;
				hash2[i][0] = niz[i][0] % MOD;
			}
		}
	}

	
	hash1_inv = power( HASH1, MOD - 2 );
	hash2_inv = power( HASH2, MOD - 2 );
	
	k = 0;
	for ( i = 0; i < n; ++i )
		for ( j = 0; j < m[i]; ++j )
			sorted[k++] = pii( i, j );
			
	sort( sorted, sorted + k, cmp );
	
	for ( i = 0; i < k; ++i )
		sort_pos[sorted[i].first][sorted[i].second] = i;
	
	
	for ( i = 0; i < n; ++i )
		s.insert( pii( i, 0 ) );
		
	pii t;
	r = 0;
	while ( !s.empty() ) {
		t = *s.begin();
		s.erase( s.begin() );
		
		result[r++] = niz[t.first][t.second];
		if ( t.second + 1 < m[t.first] ) {
			s.insert( pii( t.first, t.second + 1 ) );
		}
	}
	

	for ( i = 0; i < r; ++i )
		printf("%d ", result[i]);
	printf("\n");
	
	return 0;
}
