#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool desc(pair<int,pair<int,string> > p1, pair<int,pair<int,string> > p2) {
	if(p1.first == p2.first) return p1.second.first < p2.second.first;
	return p1.first > p2.first;
}
int main(){
	int n;
	while(cin >> n, n) {
		vector<pair<int,pair<int,string> > > v;
		int r;
		rep(i,n) {
			pair<int,pair<int,string> > p;
			cin >> p.second.second;
			rep(j,n-1) {
				cin >> r;
				if(r == 0) p.first++;
				if(r == 1) p.second.first++;
			}
			v.push_back(p);
		}
		sort(v.begin(), v.end(), desc);
		rep(i,n) {
			cout << v[i].second.second << endl;
		}
	}
	return 0;
}