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

int main(){
	int n;
	while(cin >> n && n){
		vector<string> a;
		vector< pair<int,int> > v;
		for(int i = 0 ; i < n ; i++){
			string name;
			cin >> name;
			a.push_back(name);
			int w = 0;
			for(int j = 0 ; j < n - 1 ; j++){
				int t;
				cin >> t;
				if( t == 0 ) w += 10000;
				if( t == 2 ) w += 1;
			}
			v.push_back(make_pair(-w,i));
		}
		sort(v.begin(),v.end());
		for(int i = 0 ; i < v.size() ; i++){
			cout << a[v[i].second] << endl;
		}
	}
	
}