#include<iostream>
#include<cstring>

using namespace std;

int main(void){
	int a,b,n;
	char t[10];
	int w[10],l[10];
	while(1){
		memset(w,0,sizeof(w));
		memset(l,0,sizeof(l));
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> t[a];
			for(b=0;b<n-1;b++){
				int b;
				cin >> b;
				if(b==0)w[a]++;
				if(b==1)l[a]++;
			}
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				if(w[b]>w[a] || w[b]==w[a] && l[b]<l[a])swap(t[a],t[b]),swap(w[a],w[b]),swap(l[a],l[b]);
			}
		}
		for(a=0;a<n;a++){
			cout << t[a] << endl;
		}
	}
	return 0;
}