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

bool large(pair<char, int> t1, pair<char, int> t2){
	return (t1.second > t2.second);
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		pair<char, int> teams[10];
		for(int i = 0;i < n;i++){
			cin >> teams[i].first;
			teams[i].second = 0;
			for(int j = 0;j < n - 1;j++){
				int r;
				cin >> r;
				if(r == 0) teams[i].second++;
				else if(r == 1) teams[i].second--;
			}
		}
		stable_sort(teams, teams + n, large);
		for(int i = 0;i < n;i++){
			cout << teams[i].first << endl;
		}
	}
	return 0;
}