#include using namespace std; int main() { int N; cin >> N; vector> A(N); bool check = true; int max_queue = 0, max_size = INT_MIN; for (int i = 0; i < N; i++) { int P; cin >> P; for (int j = 0; j < P; j++) { int a; cin >> a; A.at(i).push(a); } if ((int)A.at(i).size() >= max_size) { max_queue = i; max_size = A.at(i).size(); } } while (check) { check = false; for (int i = 0; i < N; i++) { if (!A.at(i).empty()) { check = true; cout << A.at(i).front(); A.at(i).pop(); if(!A.at(max_queue).empty()) cout << ' '; } } } cout << endl; }