#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL p=7+1e+9;

int main(){
	int n;
	while(cin >> n && n){
		char teams[16], c;
		ppr res[16];
		REP(i,16){
			res[i] = make_pair(-64, make_pair(64, 64));
		}
		int r;
		REP(i,n){
			cin >> c;
			teams[i] = c;
			res[i].S.S = -i;
			REP(j,n-1){
				cin >> r;
				if(r == 0){
					res[i].F++;
				}
				else if(r == 1){
					res[i].S.F--;
				}
			}
		}
		sort(res, res + n, greater<ppr>());
		REP(i,n){
			cout << teams[-res[i].S.S] << endl;
		}
	}
}