#include<iostream>
#include<vector>
using namespace std;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;
		
		vector<char> t(n);
		vector<int> win(n), lose(n), drow(n);
		vector<int> num(n);
		for (int i = 0; i < n; i++)
			num.at(i) = i;

		int score;
		for (int i = 0; i < n; i++) {
			cin >> t.at(i);
			for (int j = 0; j < n - 1; j++) {
				cin >> score;
				switch (score) {
				case(0):win.at(i)++;
				case(1):lose.at(i)++;
				case(2):drow.at(i)++;
				}
			}
		}

		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (win.at(num.at(i)) < win.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) > lose.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) == lose.at(num.at(j)) && num.at(i) > num.at(j)) {
					swap(num.at(i), num.at(j));
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << t.at(num.at(i)) << endl;
	}
}
