#include <iostream>
using namespace std;
int main()
{
	
	int n;
	char t;
	int r;
	char x[10];

	while(true){
		cin >> n;
		if(n==0)
			break;
		int win[10],lose[10];
		for(int i=0 ;i<10 ;i++){
				win[i] = 0;
				lose[i] = 0;
		}
		for(int i=0 ;i<n ;i++){
			cin >> t;

			for(int j=1 ;j<n ;j++){
				cin >> r;
				if(r==0){
					win[i]++;
				}
			   if(r==1){
					lose[i]++;
				}

			}
			x[i] = t;
		}
		char y=0,z=0;
		for(int i=0 ;i<n-1 ;i++){
				for(int j=i+1 ;j<n ;j++){
				if(win[i] < win[j]){
					z=win[i];
					win[i]=win[j];
					win[j]=z;
					y=x[i];
					x[i]=x[j];
					x[j]=y;
				}
				else if(win[i] == win[j]){
					if(lose[i] > lose[j]){
						z=win[i];
						win[i]=win[j];
						win[j]=z;
						y=x[i];
						x[i]=x[j];
						x[j]=y;
					}
				}					
			}
		}

		for(int i=0 ;i<n ;i++){
			cout << x[i] << endl;
		}
	}
	return 0;
}