#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

class Team{
  public:
  string name;
  int win;
  int lose;
  bool operator <(const Team& o) const
  {
    if(win > o.win) return true;
    if(win < o.win) return false;
    if(lose < o.lose) return true;
    return false;
  }
};

int main(void){  
  int n;
  while(cin >> n,n){
    vector<Team> t(n);
    REP(i,n){
      t[i].win = 0;
      t[i].lose = 0;
    }
    int bf;
    REP(i,n){
      cin >> t[i].name;
      REP(j,n-1){
        cin >> bf;
        if(bf==0) t[i].win++;
        if(bf==1) t[i].lose++;
      }
    }
    sort(t.begin(),t.end());
    REP(i,n)
      cout << t[i].name << endl;
  }
}