#include <iostream>
#include <algorithm>
using namespace std;
struct team{
	char name;
	int win,lose,draw;
	team(){
		win = lose = draw = 0;
	}
};
bool checker(team a,team b){
	if(a.win > b.win) return true;
	if(a.win == b.win && a.lose < b.lose) return true;
	return false;
}
int main(){
	int n,a;
	char b;
	while(cin >> n,n){
		team c[10];
		for(int i = 0;i < n;++i){
			cin >> b;
			c[i].name = b;
			for(int j = 0;j < n - 1;++j){
				cin >> a;
				if(a == 0) ++c[i].win;
				else if(a == 1) ++c[i].lose;
				else ++c[i].draw;
			}
		}
		sort(c,c+n,checker);
		for(int i = 0;i < n;++i){
			cout << c[i].name << endl;
		}
	}
	return 0;
}