#include <iostream>
#include <algorithm>
using namespace std;
int n, a; pair<int, char> d[10];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			cin >> d[i].second; d[i].first = i;
			for (int j = 0; j < n - 1; j++) {
				scanf("%d", &a);
				if (a == 0) d[i].first -= 100;
				if (a == 1) d[i].first += 10;
			}
		}
		sort(d, d + n);
		for (int i = 0; i < n; i++) printf("%c\n", d[i].second);
	}
	return 0;
}