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

class Team{
public:
  int id;
  char name;
  int win, lose;

  Team(){}
  Team(int id, char name, int win, int lose):
    id(id), name(name), win(win), lose(lose){}

  bool operator<(const Team &team)const{
    if(win == team.win){
      if(lose == team.lose){
        return id < team.id;
      }
      return lose < team.lose;
    }
    return win > team.win;
  }
};

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    Team t[n];

    for(int i = 0; i < n; i++){
      t[i].id = i;
      cin >> t[i].name;

      t[i].win = 0;
      t[i].lose = 0;

      for(int j = 0; j < n - 1; j++){
        int x;
        cin >> x;

        if(x == 0) t[i].win++;
        else if(x == 1) t[i].lose++;
      }
    }

    sort(t, t + n);

    for(int i = 0; i < n; i++){
      cout << t[i].name << endl;
    }
  }
}