#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Team
{
public:
	char name;
	int win,lose;
	Team(){
		win=lose=0;
	}
};

bool GreaterTeamCompare(const Team a,const Team b){
	if(a.win!=b.win) return a.win > b.win;
	else return a.lose < b.lose;
}

int main(void){
	int n;
	while(cin>>n,n){
		vector<Team> teams(n);
		for(int i=0;i<n;++i){
			char t; cin>>t;teams[i].name=t;
			for(int j=0,r;j<n-1;++j){
					cin>>r;
					if(r==0) ++teams[i].win;
					else if(r==1) ++teams[i].lose;
			}
		}
		sort(teams.begin(),teams.end(),GreaterTeamCompare);
		for(int i=0;i<n;++i){
			cout<<teams[i].name<<endl;
		}
	}
	return 0;
}