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

class team{
public:
  int win, lose;
  char name;
  bool operator < (const team &s)const{
    if(win==s.win){
      return lose<s.lose;
    }
    else return win>s.win;
  }
};

main(){
  int n;
  team data[10];
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      int c1=0, c2=0, tmp;
      cin >> data[i].name;
      for(int j=0;j<n-1;j++){
	cin >> tmp;
	if(tmp==0) c1++;
	else if(tmp==1) c2++;
      }
      data[i].win=c1;
      data[i].lose=c2;
    }

    stable_sort(data, data+n);

    for(int i=0;i<n;i++){
      cout << data[i].name << endl;
    }
  }
  return 0;
}