#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n;
class team {
public:
	string name;
	int win, lose;
	team()
		: win(0), lose(0)
	{
	}
};
bool teamComp(const team& x, const team& y) {
	if (x.win > y.win) return true;
	else if (x.win == y.win && x.lose < y.lose) return true;
	return false;
}

int main () {
	while (cin >> n, n) {
		team teams[n];
		for (int i = 0; i < n; i++) {
			cin >> teams[i].name;
			for (int j = 0; j < n - 1; j++) {
				int x;
				cin >> x;
				switch (x) {
				case 0:
					teams[i].win++;
					break;
				case 1:
					teams[i].lose++;
					break;
				}
			}
		}
		stable_sort(teams, teams + n, teamComp);
		for(team* it = teams; it != teams + n; it++) {
			cout << it->name << endl;
		}
	}
	return 0;
}