#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


int main() {
	int n, a;
	string s;
	while (cin >> n && n > 0) {
		vector < pair<pii, pair<int, string> > > v(n,pair<pii,pair<int,string> >(pii(0,0),pair<int,string>(0,"")));
		rep(i, n) {
			cin >> s;
			v[i].second.first = i;
			v[i].second.second = s;
			rep(j, n - 1) {
				cin >> a;
				if (a == 0) {
					v[i].first.first -= 1;
				}
				else if (a == 1) {
					v[i].first.second += 1;
				}
			}
		}
		sort(all(v));
		rep(i, n) {
			cout << v[i].second.second << endl;
		}
	}
}