#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REP(j,n) for(int j = 0; j < n; j++)

using namespace std;
typedef pair<int, int> P;
struct team {
    string name;
    int win;
    int lose;
    int number;
    team(string n, int numb) {
        name = n;
        win = 0;
        lose = 0;
        number = numb;
    }
    bool operator<( const team& right ) const {
        if(win > right.win) return 0;
        if(win < right.win) return 1;
        if(lose < right.lose) return 0;
        if(lose > right.lose) return 1;
        if(number < right.number) return 0;
        if(number > right.number) return 1;
        return 0;
    }
};
int main() {
    while(1) {
        int n;
        cin >> n;
        if(n == 0) break;
        vector<team> list;
        REP(i,n) {
            string name;
            cin >> name;
            team ck = team(name,i);
            REP(j,n-1) {
                int tmp;
                cin >> tmp;
                
                if(tmp == 0) {
                    ck.win++;
                }
                else if(tmp == 1) {
                    ck.lose++;
                }
            }
            list.push_back(ck);
        }
        sort(list.begin(),list.end());
        
        REP(i,n) {
            team ck = list.back();
            list.pop_back();
            cout << ck.name << endl;
        }
        
        
        
        
        
    }
}