#include<iostream>
#include<algorithm>
using namespace std;
typedef pair<pair<int, int>, char> p;
int main() {
	int n;
	while (cin >> n, n) {
		p a[20];
		for (int i = 0; i < n; i++) {
			cin >> a[i].second;
			a[i].first.first = 0;
			a[i].first.second = n;
			for (int j = 1; j < n; j++) {
				int k; cin >> k;
				if (!k)a[i].first.first++;
				else if (k == 1)a[i].first.second--;
			}
		}
		for (int i = n; i >= 1; i--)
			for (int j = 1; j < i; j++)
				if (a[j - 1].first < a[j].first)swap(a[j - 1], a[j]);
		for (int i = 0; i < n; i++)
			cout << a[i].second << endl;
	}
	return 0;
}
