#include<stdio.h>
#include<algorithm>
struct Team{
	int input;
	int wins;
	int loses;
	char name;
};
Team t[10];
inline bool operator<(const Team &a,const Team &b){
	if(a.wins!=b.wins)return a.wins>b.wins;
	if(a.loses!=b.loses)return a.loses<b.loses;
	return a.input<b.input;
}
int main(){
	int n;
	while(1){
		scanf(" %d ",&n);
		if(n==0)return 0;
		for(int i=0;i<n;i++){
			scanf(" %c ",&t[i].name);
			t[i].input=i;
			t[i].wins=0;
			t[i].loses=0;
			for(int j=0;j<n-1;j++){
				int val;
				scanf(" %d ",&val);
				if(val==0)t[i].wins++;
				else if(val==1)t[i].loses++;
			}
		}
		std::sort(t,t+n);
		for(int i=0;i<n;i++){
			printf("%c\n",t[i].name);
		}
	}
}