#include using namespace std; int main() { int n; cin >> n; int a, p; vector vec[1005]; for (int i = 0; i < n; i++) { cin >> p; for (int j = 0; j < p; j++) { cin >> a; vec[i].push_back(a); } reverse(vec[i].begin(), vec[i].end()); } vector ans; bool flag = true; while (flag) { flag = false; for (int i = 1; i <= n; i++) { if (vec[i].size() == 0) continue; flag = true; ans.push_back(vec[i].back()); vec[i].pop_back(); } } for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } cout << endl; return 0; }