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

struct point{
  int win, lose, draw;
  string name;

  void clear()
  {
    win = lose = draw = 0;
    name = "";
  }
};

bool operator<(point a, point b)
{
  return (a.win != b.win)? a.win > b.win: a.lose < b.lose;
}

int main()
{
  multiset<point> team;
  multiset<point>::iterator it;
  int n, i, j, m;
  string s;
  point t;
  while (cin>>n, n) {
    team.clear();
    for (i = 0; i < n; i++) {
      t.clear();
      cin>>s;
      t.name = s;
      for (j = 0; j < n-1; j++) {
	cin>>m;
	if (m == 0) t.win++;
	if (m == 1) t.lose++;
	if (m == 2) t.draw++;
      }
      team.insert(t);
    }
    for (it = team.begin(); it != team.end(); it++)
      cout<<(*it).name<<endl;
  }
  return 0;
}