#include<iostream>
#include<cstdio>
#include <cstring>
#include<map>
#include<string>
#include<stack>
#include <algorithm>
#include <sstream>
#include<vector>
using namespace std;


int main(void){
	multimap<int,char,greater<int> > team;
	char t;
	int n;

	while(1)
	{
		cin>>n;
		if(!n) break;
		
		for(int j=0; j<n; j++)
		{
			cin>>t;
			int point=0,r;
			
			for(int i=0; i<n-1; i++)
			{
				cin>>r;
				if(r==0) ++point;
				else if(r==1) --point;
			}
			team.insert( make_pair( point,t) );
		}

		for(multimap<int,char,greater<int> >::iterator it=team.begin(); it != team.end(); ++it)
			cout<<(*it).second<<endl;
		team.clear();
	}
	return 0;
}