#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int a,n,k[10],m[10];
  char c[10];
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(k,0,sizeof(k));
    memset(m,0,sizeof(m));
    for(i=0;i<n;i++){
      cin>>c[i];
      for(j=0;j<n-1;j++){
	cin>>a;
	if(a==0)
	  k[i]++;
	else if(a==1)
	  m[i]++;
      }
    }
    do{
      h=0;
      for(i=1;i<n;i++){
	if(k[i-1]<k[i]){
	  swap(k[i-1],k[i]);
	  swap(m[i-1],m[i]);
	  swap(c[i-1],c[i]);
	  h=1;
	}else if(k[i-1]==k[i]){
	  if(m[i-1]>m[i]){
	    swap(k[i-1],k[i]);
	    swap(m[i-1],m[i]);
	    swap(c[i-1],c[i]);
	    h=1;
	  }
	}
      }
    }while(h);
    for(i=0;i<n;i++)
      cout<<c[i]<<endl;
  }
  return 0;
}