#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

int main(){
  pair<int,char> game[10];
  int team,point[10][10],ten[10];
  
  while(1){
    for(int i=0;i<10;i++){
      ten[i] = 0;
    }
    cin >> team;
    if(team == 0)break;

    for(int i=0;i<team;i++){
      cin >> game[i].second;
      for(int j=0;j<team-1;j++){
	cin >> point[i][j];
	if(point[i][j] == 0){
	  ten[i] += 2;
	}
	else if(point[i][j] == 2){
	  ten[i]++;
	}
      }
      game[i].first = ten[i];
    }
    sort(game,game+team);

    for(int i=team-1;0<=i;i--){
      cout << game[i].second << endl;
    }
  }
  return 0;
}