#include <iostream>
#include <set>
#include <functional>
#include <cstdio>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

struct Team {
  char name;
  int win,lose,id;
  Team(int i):win(0),lose(0),id(i){}
  bool operator>(const Team& a) const {
    if (win == a.win && lose == a.lose) return id < a.id;
    if (win != a.win) return win > a.win;
    return lose < a.lose;
  }
};

int n;

void solve() {
  set<Team, greater<Team> > teams;
  rep(i,n) {
    Team team(i);
    cin>>team.name;
    rep(j,n-1) {
      int t; cin>>t;
      if (t == 0) team.win++;
      else if (t == 1) team.lose++;
    }
    teams.insert(team);
  }
  
  set<Team>::iterator it = teams.begin();
  while (it != teams.end()) {
    cout<<it->name<<endl;
    it++;
  }
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}