#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

int main(){
  int n;
  while(cin >> n, n!=0){
    vector<pair<int, char>> v;

    for(int i=0; i<n; ++i){
      char tmp;
      cin >> tmp;
      v.push_back(make_pair(0, tmp));
      
      for(int j=0; j<n-1; ++j){
	int scr;
	cin >> scr;
	
	if(scr==0){
	  v[i].first = v[i].first + 10;
	}else if(scr==2){
	  v[i].first = v[i].first + 1;
	}
      }
      
    }
    //sort(v.begin(), v.end(), greater<pair<int, char>>());
    //reverse(v.begin(), v.end());
    for(int i=0; i<n; ++i){
      for(int j=0; j<n-1; ++j){
	if(v[j].first < v[j+1].first){
	  pair<int, char> pr;
	  pr = v[j];
	  v[j] = v[j+1];
	  v[j+1] = pr;
	}
      }
    }
    
    for(auto i: v){
      cout << i.second << endl;
    }
  }
  return 0;
}
	 

