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

using namespace std;

struct DATA{
  char Team;
  int Win;
  int Lose;
};

bool compare(const DATA&, const DATA&);

int main(){
  int i, j, n, score, win, lose;
  char c;
  DATA one;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> c;

      win = 0;
      lose = 0;
      for(j=0; j<n-1; ++j){
	cin >> score;
	if(score == 0) win++;
	else if(score == 1) lose++;
      }
      one.Team = c;
      one.Win = win;
      one.Lose = lose;
      data.push_back(one);
    }

    sort(data.begin(), data.end(), compare);
    for(i=0; i != data.size(); ++i)
      cout << data[i].Team << endl;
    data.clear();
  }

  return 0;
}

bool compare(const DATA& x, const DATA& y){
  if(x.Win == y.Win)
    return x.Lose < y.Lose;
  else
    return x.Win > y.Win;
}