#include int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); std::vector a[n]; for (int i = 0; i < n; i++) { a[i].resize(ri()); for (auto &j : a[i]) j = ri(); std::reverse(a[i].begin(), a[i].end()); } std::vector res; for (;;) { bool cont = false; for (int i = 0; i < n; i++) { if (a[i].size()) res.push_back(a[i].back()), a[i].pop_back(), cont = true; } if (!cont) break; } for (auto i : res) std::cout << i << " "; std::cout << std::endl; return 0; }