#include<iostream>
#include<algorithm>
#include<vector>
class team {
public:
	char name;
	int win;
	int lose;
	team() :win(0), lose(0) {}
};

bool compare(team &a, team &b) {
	return a.win > b.win || (a.win == b.win&&a.lose < b.lose);
}
using namespace std;

int main() {
	int num;
	while (cin >> num&&num != 0) {
		vector<team> line(num);
		for (int i = 0; i < num; ++i) {
			cin >> line[i].name;
			for (int j = 0, nmax = num - 1; j < nmax; ++j) {
				int result;
				cin >> result;
				if (result == 0) {
					++line[i].win;
				}
				else if (result == 1) {
					++line[i].lose;
				}
			}
		}
		sort(line.begin(), line.end(), compare);
		for (int i = 0; i < num; ++i) {
			cout << line[i].name << endl;
		}
	}
	return 0;
}