#include<iostream>
using namespace std;

class team{
public:
	int w,l;
	char name;
	team(){
		w = l = 0;
	}
	void clear(){
		w = l = 0;
	}
}T[10];

void sort(int *a, int n){
	for(int i=1; i<n; i++){
		if(T[a[i-1]].w < T[a[i]].w || (T[a[i-1]].w == T[a[i]].w && T[a[i-1]].l > T[a[i]].l)){
			int tmp = a[i];
			a[i] = a[i-1];
			a[i-1] = tmp;
			i=0;
		}
	}
}

int main(){
	int n,tmp;
	char ntmp;
	int ans[10];
	while(true){
		cin >> n;
		if(n==0)
			break;
		for(int i=0; i<n; i++){
			ans[i] = i;
			cin >> ntmp;
			T[i].name = ntmp;
			for(int j=0; j<n-1; j++){
				cin >> tmp;
				if(tmp == 0)
					T[i].w++;
				else if(tmp == 1)
					T[i].l++;
			}
		}
		sort(ans, n);
		for(int i=0; i<n; i++){
			cout << T[ans[i]].name << endl;
			T[i].clear();
		}
	}
	return 0;
}