#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

struct Team{
	char name;
	int win, lose;
	bool operator < (const Team &a) const{
		return (win == a.win) ? lose < a.lose : win > a.win;
	}
};

int main(){
	int N, R;
	while(cin >> N, N){
		Team t[10] = {};
		for(int i = 0; i < N; i++){
			cin >> t[i].name;
			for(int j = 0; j < N-1; j++){
				cin >> R;
				if(R == 0) t[i].win++;
				if(R == 1) t[i].lose++;
			}
		}

		sort(t, t + N);

		for(int i = 0; i < N; i++){
			printf("%c\n", t[i].name);
		}
	}
	return 0;
}