#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		vector<pair<pair<int,int>,pair<int,char> > > v;
		for(int i = 0; i < n; i++){
			char ch;
			int w,l;
			w=l=0;
			cin>>ch;
			for(int j = 0; j < n-1; j++){
				int t;
				cin>>t;
				if(t==0)
					w++;
				else if(t==1)
					l++;
			}

			v.push_back(make_pair(make_pair(-w,l),make_pair(i,ch)));
		}
		sort(v.begin(),v.end());
		for(int i = 0; i < v.size(); i++){
			cout<<v[i].second.second<<endl;
		}
	}


	return 0;
}