#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int n,r,team[10]={0},t;
	char name[10],T;
	while(1){
		for(int i=0;i<10;i++) team[i]=0;
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			for(int j=0;j<n-1;j++){
				cin >> r;
				if(r==0)
					team[i] = team[i] + 2;
				else if(r==2)
					team[i] = team[i] + 1;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(team[i] < team[j]){
					t = team[i];
					team[i] = team[j];
					team[j] = t;
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << name[i] << endl;
		}
	}
	return 0;
}