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

struct Data{
  string name;
  int win;
  int lose;
};

vector<Data> team;

bool comp(const Data& d1, const Data& d2){
  if(d1.win == d2.win) return (d1.lose < d2.lose);
  return (d1.win > d2.win);
}

int main(void){
  int n;
  while(cin >> n, n != 0){
    team.clear();
    for(int i = 0; i < n; i++){
      Data t;
      cin >> t.name;
      t.win = 0; t.lose = 0;
      for(int j = 0; j < n - 1; j++){
        int res;  cin >> res;
        if(res == 0) t.win++;
        if(res == 1) t.lose++;
      }
      team.push_back(t);
    }
    sort(team.begin(), team.end(), comp);
    for(int i = 0; i < team.size(); i++){
      cout << team[i].name << endl;
    }
  }
  return 0;
}