#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct data{
	string team;
	int win, lose, order;
};

bool cmp(data d1, data d2){
	if(d1.win != d2.win) return d1.win > d2.win;
	if(d1.lose != d2.lose) return d1.lose < d2.lose;
	return d1.order < d2.order;
}

signed main() {
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		vector<data> d(n);
		string s;
		int a, win, lose;
		rep(i, 0, n){
			cin >> s;
			win = 0;
			lose = 0;
			rep(j, 0, n - 1){
				cin >> a;
				if(a == 0) win++;
				else if(a == 1) lose++;
			}
			d[i].team = s;
			d[i].win = win;
			d[i].lose = lose;
			d[i].order = i;
		}
		sort(all(d), cmp);
		rep(i, 0, n){
			cout << d[i].team <<endl;
		}
	}
}