#include<iostream>
#include<algorithm>
#include<functional>
#define MAX 11
using namespace std;
class Team{
public:
  char name;
  int wins;
  int loses;
  int id;
  Team():id(0),wins(0),loses(0){}
  bool operator>(const Team &t)const{
    if( wins == t.wins ){
      if( loses == t.loses ){
	return id < t.id;
      }else return loses < t.loses;
    }else return wins > t.wins;
  }
};
int main()
{
  while(true){
    int n;
    cin >> n;
    if( n == 0 ) break;
    Team teams[n];
    for(int i = 0; i < n; ++i){
      teams[i].id = i;
      char name;
      cin >> name;
      teams[i].name=name;
      for(int j = 0; j < n-1; ++j){
	int r;cin>>r;
	if(r==0)teams[i].wins++;
	if(r==1)teams[i].loses++;
      }
    }
    sort(teams,teams+n,greater<Team>());
    for(int i = 0; i < n; ++i){
      cout << teams[i].name << endl;
    }
  }
  return 0;
}