#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
struct team{
    char name;
    int win=0,lose=0,draw=0;
    bool operator<(const team &a)const{
        if(win==a.win)return lose<a.lose;
        return win>a.win;
    }
};
int main(){
    while(1){
        int n;
        team teams[10];
        cin>>n;
        if(!n)break;
        for(int i=0;i<n;i++){
            cin>>teams[i].name;
            for(int j=0;j<n-1;j++){
                int a;
                cin>>a;
                if(a==0)teams[i].win++;
                else if(a==1)teams[i].lose++;
                else teams[i].draw++;
            }
        }
        sort(teams,teams+n);
        for(int i=0;i<n;i++){
            cout<<teams[i].name<<endl;
        }
    }
    return 0;
}