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

struct team{
	char t;
	int w, l;
};

bool large(team t1, team t2){
	return ((t1.w > t2.w) || (t1.w == t2.w && t1.l < t2.l));
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		team teams[10] = {0};
		for(int i = 0;i < n;i++){
			cin >> teams[i].t;
			for(int j = 0;j < n - 1;j++){
				int r;
				cin >> r;
				if(r == 0) teams[i].w++;
				if(r == 1) teams[i].l++;
			}
		}
		stable_sort(teams, teams + n, large);
		for(int i = 0;i < n;i++){
			cout << teams[i].t << endl;
		}
	}
	return 0;
}