#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	int n;
	while(cin>>n,n){
		multimap<int,string,greater<int> > ranking;
		for(int i=0;i<n;++i){
			string s;
			int win=0,lose=0;
			cin>>s;
			for(int j=0,score;j<n-1;++j){
				cin>>score;
				if(score==0) win++;
				else if(score==1) lose++;
			}
			ranking.insert(multimap<int,string>::value_type(win+n-1-lose,s));
		}
		multimap<int,string,greater<int> >::iterator it;
		for(it=ranking.begin();it!=ranking.end();++it){
			cout<<(*it).second<<endl;
		}
	}
	return 0;
}