#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

struct Team{
	char name[2];
	int win,lose;
};

int main(){

	int n,tmp;
	Team team[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0;i < n; i++){
			team[i].win = 0;
			team[i].lose = 0;
		}

		for(int i = 0; i < n; i++){
			scanf("%s",team[i].name);

			for(int k = 0; k < n-1; k++){
				scanf("%d",&tmp);
				if(tmp == 0)team[i].win++;
				else if(tmp == 1)team[i].lose++;
			}
		}

		for(int i=1; i <= n-1; i++){
			for(int k=n-1; k >= i; k--){
				if(team[k].win > team[k-1].win)swap(team[k],team[k-1]);
				else if(team[k].win == team[k-1].win && team[k].lose < team[k-1].lose)swap(team[k],team[k-1]);
			}
		}

		for(int i = 0; i < n; i++){
			printf("%s\n",team[i].name);
		}

	}

	return 0;
}