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

struct Team {
  string name;
  int game[3];
  
  bool operator<(const Team &t) const {
    if( game[0] != t.game[0] ) return game[0] > t.game[0];
    if( game[1] != t.game[1] ) return game[1] < t.game[1];
    return false;
  }
};

int main() {
  for( int N; cin >> N, N;  ) {
    
    Team team[N];

    for(int i = 0; i < N; i++) {
      cin >> team[i].name;
      for(int j = 0; j < 3; j++) team[i].game[j] = 0;

      for(int j = 0; j < N - 1; j++) {
        int x; cin >> x;
        team[i].game[x]++;
      }
    }
    
    sort( team, team + N );
    for(int i = 0; i < N; i++) cout << team[i].name << endl;

  }
}