#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

struct st {
	char a;
	int b, c;
};
int main() {
	int n;
	while (cin >> n, n) {
		vector<st>v;
		rep(i, n) {
			char t; int a = 0, b = 0;
			cin >> t;
			rep(j, n - 1) {
				int r; cin >> r;
				if (!r)a++;
				if (r == 1)b++;
			}
			v.push_back({ t,a,b });
		}
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.c < b.c; });
		stable_sort(v.begin(), v.end(), [](st a, st b) {return a.b > b.b; });
		for (st i : v) {
			cout << i.a << endl;
		}
	}
}