#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<pair<string, int>>v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i].first;
			for (int j = 0; j < n - 1; j++) {
				int num;
				cin >> num;
				if (num == 0) v[i].second += 100;
				if (num == 1) v[i].second -= 1;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (v[j].second > v[j - 1].second) swap(v[j], v[j - 1]);
			}
		}
		for (int i = 0; i < n; i++) {
			cout << v[i].first << endl;
		}
	}
	return 0;
}