#include <iostream>
#include <algorithm>
#include <string>

struct Team {
	char name;
	int wins;
	int loss;
};
bool operator > (const Team& t1, const Team& t2) {
	if (t1.wins > t2.wins) return true;
	else if (t1.wins < t2.wins) return false;
	else return t1.loss < t2.loss;
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			char c; std::cin >> c;
			teams[i].name = c;
			int wins = 0;
			int loss = 0;
			for (int j=0; j<n-1; j++) {
				int x; std::cin >> x;
				if (x==0) wins++;
				else if (x==1) loss++;
			}
			teams[i].wins = wins;
			teams[i].loss = loss;
		}
		std::sort(teams, teams + n, std::greater<Team>());
		for (int i=0; i<n; i++) std::cout << teams[i].name << std::endl;
		delete[] teams;
	}
	return 0;
}

