#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(){
  int n;

  while(1) {
  cin >> n;
  if(n == 0) break;
  vector <int> v,lo;

  string str[10];
  v.resize(n);
  lo.resize(n);
  for(int i=0;i<n;i++) v[i] = lo[i] = 0;
  
  int a;
  for(int i=0;i<n;i++) {
    cin >> str[i];
    for(int j=0;j<n-1;j++) {
      cin >> a;
      if(a ==0) v[i]++;
      else if(a == 1) lo[i]++;
      
    }
  }
  
  string t;

  for(int i=0;i<n-1;i++) {
    for(int j=n-1;j>i;j--) {
      if(v[j] > v[j-1]) {
	t = str[j];
	str[j] = str[j-1];
	str[j-1]  = t;
	
	a = v[j];
	v[j] = v[j-1];
	v[j-1] = a;
	
	a = lo[j];
	lo[j] = lo[j-1];
	lo[j-1] = a;
	
      } else if(v[j] == v[j-1] && lo[j] < lo[j-1]) {
	t = str[j];
	str[j] = str[j-1];
	str[j-1] = t;

	a = lo[j];
	lo[j] = lo[j-1];
	lo[j-1] = a;
      }
    }
  }
      for(int i=0;i<n;i++) cout << str[i] << endl;

  } 


  return 0;
}