#include <iostream>
#include <stdio.h>
using namespace std;
struct base{
	char team;
	int win;
	int lose;
};

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		struct base champ[10];
		for(int i=0;i<n;i++){
			champ[i].win = 0;
			champ[i].lose = 0;
		}
		for(int i=0;i<n;i++){
			cin>>champ[i].team;
			for(int j=0;j<n-1;j++){
				int a;
				cin>>a;
				if(a==0) champ[i].win++;
				else if(a==1) champ[i].lose++;
			}
		}
		struct base temp;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(champ[i].win < champ[j].win){
					temp = champ[i];
					champ[i] = champ[j];
					champ[j] = temp;
				}else if(champ[i].win == champ[j].win){
					if(champ[i].lose > champ[j].lose){
						temp = champ[i];
						champ[i] = champ[j];
						champ[j] = temp;
					}
				}
			}
		}

		for(int i=0;i<n;i++){
			cout<<champ[i].team<<endl;
		}
	}

	return 0;
}