#include <iostream>
#include <vector>
#include <algorithm>

struct team{std::string name; int win; int lose;};

bool ascendingteam(const team& lteam, const team& rteam){
  if(lteam.win == rteam.win)
    return lteam.lose < rteam.lose;
  return lteam.win > rteam.win;  
}

int main(){
  int n;
  while(std::cin >> n, n){
    std::vector<team> tv;
    for(int j=0;j<n;j++){
      team t;
      t.win = 0, t.lose = 0;
      std::string name;
      std::cin >> name;
      t.name = name;
      for(int i=0;i<n-1;i++){
        int point;
        std::cin >> point;
        if(point == 0)
          t.win++;
        else if(point == 1)
          t.lose++;
      }
      tv.push_back(t);
    }

    std::sort(tv.begin(), tv.end(), ascendingteam);
    
    std::vector<team>::iterator it = tv.begin();
    while(it != tv.end()){
      std::cout << (*it).name << std::endl;
      it++;
    }
  }
}