#include using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; using i128 = __int128; void solve() { int N; std::cin >> N; std::vector> A(N); std::queue ans; int max = -1; for(int i = 0; i < N; i ++) { int p; std::cin >> p; max = std::max(max, p); while(p -- ) { int a; std::cin >> a; A[i].push(a); } } for(int i = 0; i < max; i ++) { for(int j = 0; j < N; j ++) { if(!A[j].empty()) { int a = A[j].front(); A[j].pop(); ans.push(a); } } } while(!ans.empty()) { int a = ans.front(); ans.pop(); std::cout << a << " "; } std::cout << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; //std::cin >> T; while (T--) { solve(); } return 0; }