#include <stdio.h>
const int N=11;
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
int main(){
    int n,temp,w[N],l[N],f[N];
    char c[10],a[N];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            scanf("%s",c);
            a[i]=c[0];
            f[i]=i;
            w[i]=l[i]=0;
            for(int j=1;j<n;j++){
                scanf("%d",&temp);
                if(temp==1)l[i]++;
                else if(temp==0)w[i]++;
            }
        }
        for(int i=0;i<n;i++)for(int j=1;j<n;j++)if(w[f[j]]==w[f[j-1]]?l[f[j]]<l[f[j-1]]:w[f[j]]>w[f[j-1]])swap(f[j],f[j-1]);
        
        
        for(int i=0;i<n;i++)printf("%c\n",a[f[i]]);
    }
}
