#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> P2;

int main(){
  int n;
  P2 team[11];
  map<int, char> names;
  while(cin >> n, n){
    names.clear();
    for(int i = 0 ; i < n ; i++){
      team[i].first = 0;
      team[i].second.first = 0;
    }
    int cnt = 0;
    char name;
    int op;
    for(int i = 0 ; i < n ; i++){
      cin >> name;
      team[i].second.second = cnt;
      names.insert(make_pair(cnt++, name));
      for(int j = 0 ; j < n-1 ; j++){
	cin >> op;
	if(op == 0) team[i].first++;
	if(op == 1) team[i].second.first++;
      }
    }
    
    for(int i = 0 ; i < n ; i++){
      team[i].first *= -1;
    }
    
    stable_sort(team, team+n);
    //reverse(team, team+n);
    
    for(int i = 0 ; i < n ; i++){
      cout << names[team[i].second.second] << endl;
    }
  }
  return 0;
}