#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<pair<int, int>, pair<int, string> > > team(n);
        for(int i=0; i<n; ++i){
            team[i].second.first = -i;
            cin >> team[i].second.second;
            for(int j=0; j<n-1; ++j){
                int a;
                cin >> a;
                if(a == 0)
                    ++ team[i].first.first;
                else if(a == 1)
                    -- team[i].first.second;
            }
        }
        sort(team.rbegin(), team.rend());

        for(int i=0; i<n; ++i)
            cout << team[i].second.second << endl;
    }
}