#include<iostream>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;

int main(){

  int n;
  char c[11];
  int dat[11][11];
  typedef pair < int, pair < int, char > > P; //win, lose, name
  P team[11];

  while(cin >> n, n){

    for(int i=0;i<n;i++){
      cin >> team[i].S.S;
      for(int j=0;j<n-1;j++){
	cin >> dat[i][j];
	if(dat[i][j] == 1) team[i].S.F--;
	if(dat[i][j] == 0) team[i].F++;
      }
    }
    
    sort(team, team+n);
    reverse(team, team+n);

    for(int i=0;i<n;i++) cout << team[i].S.S << endl;
  }
}