#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

typedef struct{
    int win,lose;
}Score_t;


bool comp(const pair<Score_t,char>& x, const pair<Score_t,char>& y){
    if(x.first.win == y.first.win)return x.first.lose < y.first.lose;
    return x.first.win > y.first.win;
}


int main(){
        
    int n;
    vector<pair<Score_t,char> > score;
    
    while(cin>>n, n!=0){
        score.clear();
        
        
        for(int i=0; i<n; i++){
            char id; cin >> id;
            Score_t tmp={0,0};
            for(int j=0; j<n-1; j++){
                int in;
                cin >>in;
                if(in==0)tmp.win++;
                else if(in==1)tmp.lose++;
            }
        
            score.push_back(make_pair(tmp,id));
        }
        
        sort(score.begin(),score.end(),comp);
        for(int i=0; i<n; i++)cout << score[i].second << endl;
    }
    return 0;
}


