#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> Pi;

int main(){
  int n;
  while(cin >> n , n){
    Pi match[10];
    string team[10];
    for(int i=0;i<n;i++){
      cin >> team[i];
      match[i].first.first = 0; match[i].first.second = 0;
      match[i].second = i;
      for(int j=0;j<n-1;j++){
	int a; cin >> a;
	if(a == 0) match[i].first.first--;
	else if(a == 1) match[i].first.second++;
    }
    }
    sort(match,match+n);
    for(int i=0;i<n;i++){
      cout << team[match[i].second] << endl;
    }
  }
}