#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

bool ij(vector<int> i, vector<int> j) {
    int a = i.size();
    int b = j.size();
    int c = max(a,b)-min(a,b);
    double ans1 = 1.0;
    double ans2 = 1.0;
    if(a>b) {
        for(int it = 1; it <= c+1; it++) {
            ans1 = pow((double)i[a-it], ans1);
        }
        ans2 = (double)j[b-1];
    } else if(b>a) {
        for(int it = 1; it <= c+1; it++) {
            ans2 = pow((double)j[b-it], ans2);
        }
        ans1 = (double)i[a-1];
    } else {
        ans1 = (double)i[a-1];
        ans2 = (double)j[b-1];
    }
    c = min(a,b);
    double da, db;
    for(int it = 2; it <= c; it++) {
        da = log2((double)i[c-it])*ans1;
        db = log2((double)j[c-it])*ans2;
        if(da>db) {
            ans1=pow(2,da-db);
            ans2=1.0;
        } else if(da<db) {
            ans2=pow(2,db-da);
            ans1=1.0;
        }
    }
    return ans1<ans2;
}

int main()
{
    int n;
    cin >> n;
    int k, t;
    vector<int> vt(10);
    bool bo;
    vector<vector<int> > vc(n,vt);
    for(int i = 0; i < n; i++) {
        cin >> k;
        bo = true;
        k++;
        vc[i].reserve(k);
        for(int j = 0;j < k; j++) {
            cin >> t;
            if(t==1) {
                bo = false;
                if(j==0) {
                    vc[i].push_back(1);
                }
            } else if(bo) {
                vc[i].push_back(t);
            }
        }
    }
    vector<vector<int> > hu = vc;
    sort(vc.begin(), vc.end(), ij);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(vc[i]==hu[j]) {
                cout << j+1 << " ";
                break;
            }
        }
    }
    cin >> n;
    return 0;
}
