#include<iostream>
using namespace std;
int main()
{
	int n,r,wint[10],loset[10],t;
	char name[11],T;
	while(1){
		for(int i=0;i<10;i++){
			wint[i]=0;
			loset[i] = 0;
		}
		cin >> n;
		if(n == 0) break;
		for(int i=0;i<n;i++){
			cin >> name[i];
			for(int j=0;j<n-1;j++){
				cin >> r;
				if(r==0)
					wint[i]++;
				else if(r==1)
					loset[i]++;
			}
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(wint[i] < wint[j]){
					t = wint[i];
					wint[i] = wint[j];
					wint[j] = t;
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
				else if(wint[i] == wint[j] && loset[i] > loset[j]){
					T = name[i];
					name[i] = name[j];
					name[j] = T;
				}
			}
		}
		for(int i=0;i<n;i++){
			cout << name[i] << endl;
		}
	}
	return 0;
}