#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int team[n][n-1];
		char name[n];
		rep(i,n){
			cin>>name[i];
			rep(j,n-1){
				cin>>team[i][j];
			}
		}
		int win[n];
		int lose[n];
		rep(i,n){
			win[i]=0;
			lose[i]=0;
		}
		rep(i,n){
			rep(j,n-1){
				if(team[i][j]==0)win[i]++;
				else if(team[i][j]==1)lose[i]++;
			}
		}
		rep(i,n){
			for(int j=n-2;j>=i;j--){
				if(win[j+1]>win[j]){
					int alt=win[j];
					win[j]=win[j+1];
					win[j+1]=alt;
					alt=lose[j];
					lose[j]=lose[j+1];
					lose[j+1]=alt;
					char c=name[j];
					name[j]=name[j+1];
					name[j+1]=c;
				}else if(win[j+1]==win[j]){
					if(lose[j+1]<lose[j]){
						int alt=win[j];
						win[j]=win[j+1];
						win[j+1]=alt;
						alt=lose[j];
						lose[j]=lose[j+1];
						lose[j+1]=alt;
						char c=name[j];
						name[j]=name[j+1];
						name[j+1]=c;
					}
				}
			}
		}
		rep(i,n){
			cout<<name[i]<<endl;
		}
	}
	return 0;
}