#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		// <<勝ち数, -負け数>, 入力順>, 名前
		vector<pair<pair<pair<int, int>, int>, string>> d(n);

		rep(i, n) {
			string name; cin >> name;
			int c0 = 0, c1 = 0, c2 = 0;
			rep(j, n - 1) {
				int x; cin >> x;
				switch (x) {
				case 0:
					c0++; break;
				case 1:
					c1++; break;
				case 2:
					c2++; break;
				}
			}

			d[i] = mp(mp(mp(-c0, c1), i), name);
		}

		sort(all(d));

		rep(i, n)Cout(d[i].second);
	}
}
