#include <bits/stdc++.h>
using namespace std;

bool compare(pair< string, pair< int, int > > a, pair< string, pair< int, int > > b){
	if(a.second.first != b.second.first){
		return a.second.first > b.second.first;
	}
	
	return a.second.second < b.second.second;
}

int main(){
	int n;
	vector< pair< string, pair< int, int > > > team;
	
	while(cin >> n, n){
		team.clear();
		team.resize(n);
		
		string str;
		int s, w, l;
		
		for(int i = 0; i < n; ++i){
			cin >> str;
			w = l = 0;
			for(int j = 0; j < n - 1; ++j){
				cin >> s;
				if(s == 0) ++w;
				else if(s == 1) ++l;
			}
			
			team[i] = make_pair< string, pair< int, int > >(str, make_pair< int, int >(w, l) );
		}
		
		sort(team.begin(), team.end(), compare);
		
		for(vector< pair< string, pair< int, int > > >::iterator it = team.begin(); it != team.end(); ++it){
			cout << it->first << endl;
		}
		
	}
	
	return 0;
}