#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; V< queue > qs(n); for (int i = 0; i < n; ++i) { int p; cin >> p; while (p--) { int a; cin >> a; qs[i].push(a); } } V<> res; while (true) { bool b = false; for (int i = 0; i < n; ++i) if (!qs[i].empty()) { res.push_back(qs[i].front()); qs[i].pop(); b = true; } if (!b) break; } int m = res.size(); for (int i = 0; i < m; ++i) { cout << res[i] << " \n"[i == m - 1]; } }