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

bool cmp(pair<string,pair<int,int> > a, pair<string,pair<int,int> > b){
	a.second > b.second;
}

int main(){
	
	int n;
	int t;
	while(cin >> n && n){
		vector<pair<string,pair<int,int> > > team(n);
		
		for(int i=0;i<n;i++){
			cin >> team[i].first;
			for(int j=0;j<n-1;j++){
				cin >> t;
				if(t==0)team[i].second.first++;
				if(t==1)team[i].second.second--;
			}
		}
		stable_sort(team.begin(),team.end(),cmp);
		
		for(int i=0;i<team.size();i++){
			cout << team[i].first << endl;
		}
	}
}