#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int n;
	while(cin >> n, n) {
		vector<pair<pair<int,int>, pair<int,string> > > v;
		for(int i = 0; i < n; i++) {
			string s;
			int win = 0;
			int lose = 0;
			cin >> s;
			for(int j = 0; j < n - 1; j++) {
				int t;
				cin >> t;
				if(t == 0)
					win--;
				else if(t == 1)
					lose++;
			}
			v.push_back(pair<pair<int,int>,pair<int,string> >(pair<int,int>(win, lose), pair<int,string>(i,s)));
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < v.size(); i++) {
			cout << v[i].second.second << endl;
		}
	}
}