#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct data{
    int w,l,p;
    char name;
    data(int a,int b,int c,char d):w(a),l(b),p(c),name(d){}
    data(){}
    bool operator<(const data &d)const{
        if(w!=d.w)return w<d.w;
        if(l!=d.l)return l>d.l;
        return p>d.p;
    }
};
int main(){
    int n;
    while(scanf("%d",&n),n){
        vector<data>V;
        for(int i=0;i<n;i++){
            char c;
            scanf(" %c",&c);
            int w,l;
            w=l=0;
            for(int j=0;j<n-1;j++){
                int val;
                scanf("%d",&val);
                if(val==2)continue;
                if(val)w++;
                else l++;
            }
            V.push_back(data(w,l,i,c));
        }
        sort(V.begin(),V.end());
        for(int i=0;i<n;i++){
            printf("%c\n",V[i].name);
        }

    }
    return 0;
}