#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


int main()
{
	int n; 
	while (cin >> n, n) {
		vector<plc> v(n);

		for (int i = 0; i < n; i++) {
			cin >> v[i].second;
			int num = 0;
			for (int j = 0; j < n - 1; j++) {
				int x; cin >> x;
				if (x == 0)num += 100000;
				if (x == 1)num--;
			}
			v[i].first = num;
		}

		for (int i = 0; i < n-1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (v[i].first < v[j].first)
					swap(v[i], v[j]);
			}
		}

		for (int i = 0; i < n; i++) {
			cout << v[i].second << endl;
		}
	}
	return 0;
}