#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int t,n,k=0;
    scanf ("%d",&t);
    vector <vector <int> > a;
    vector <int> sol;
    for (int i=0; i<t; i++) {
        vector <int> b;
        int c;
        scanf ("%d",&n);
        while (n--){scanf ("%d",&c); b.insert(b.begin(),c);k++;}
        a.push_back(b);
        }
    for (int stop=0; stop<k; stop++){
        pair <int,int> test; test.first=100000000;
        for (int i=0; i<t; i++){ if (a[i].back()<test.first){test.first=a[i].back(); test.second=i;}
                                 else if (a[i].back()==test.first){
                                            int r=2;
                                            while (a[i].size()-r >=0 and a[test.second].size()-r >=0){
                                                if (a[i][a[i].size()-r] < a[test.second][a[test.second].size()-r]){test.first=a[i].back(); test.second=i; break;}
                                                else if (a[i][a[i].size()-r] == a[test.second][a[test.second].size()-r]) r++;
                                                else break;
                                                }
                                            }
                                }
        sol.push_back(a[test.second].back());
        a[test.second].pop_back();
        }
    for (int i=0; i<sol.size(); i++) cout << sol[i] << " ";
    return 0;
}
