#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<string>s(n);
	vector<int>p(n);
	vector<int>m(n);
	rep(i,n){
	  cin>>s[i];
	  int tmp;
	  rep(j,n-1){
	    cin>>tmp;
		if(!tmp)p[i]++;
		else if(tmp==1)m[i]++;
	  }
	}
	rep(i,n){
	  rep(j,n-i-1){
	    if(p[j]<p[j+1]||(p[j]==p[j+1]&&m[j]>m[j+1])){
		  swap(s[j],s[j+1]);
		  swap(m[j],m[j+1]);
		  swap(p[j],p[j+1]);
		}
	  }
	}
	rep(i,n)cout<<s[i]<<endl;
  }
}