#include using namespace std; typedef long long ll; int main() { int N; scanf("%d", &N); vector< queue > A(N); int q = 0; for (int i = 0; i < N; ++i) { int P; scanf("%d", &P); q += P; for (int j = 0; j < P; ++j) { int a; scanf("%d", &a); A[i].push(a); } } while (q > 0) { for (int i = 0; i < N; ++i) { if (!A[i].empty()) { int next = A[i].front(); A[i].pop(); if (q == 1) cout << next << endl; else cout << next << " "; q--; } } } return 0; }