#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	char ti[10000];
	int ho[10000];
	while(1){
		int n,win[10000]={},lose[100000]={},blow[100000]={};
	
		cin >> n;
		if(n == 0) break;
		for(int i=0;i < n;i++){
			cin >> ti[i];
			for(int j=0;j<n-1;j++){
				cin >> ho[j];
				if(ho[j] == 0) win[i]+=1;
				if(ho[j] == 1) lose[i]+=1;
			}
		}for(int i=0;i<n;i++){
			for(int j=0;j+1<n;j++){
				if(win[j] < win[j+1] || (win[j]==win[j+1] && lose[j] > lose[j+1]) ){
					swap(lose[j],lose[j+1]);	
					swap(win[j],win[j+1]);	
					swap(ti[j],ti[j+1]);
				}
			}
		}for(int i=0;i<n;i++){
		 cout << ti[i] << endl;	
		}
	}
}