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


using namespace std;
struct node{
  char name;
  int win,lost;
  node(char n,int w, int l): name(n),win(w), lost(l){}
  bool operator <(const node &e) const{
    if(win == e.win)
	return lost < e.lost;
    else
      return win > e.win;
  }

  bool operator >(const node &e) const{
    if(win == e.win)
      return lost > e.lost;
    else
      return win < e.win;
      }
};


int main()
{
  int n;
  for(;cin>>n,n;)
    {
      vector<node> data;
      for(int i=0;i<n;i++)
	{
	  char t;
	  cin>>t;
	  int win=0;
	  int lost=0;
	  for(int i=1;i<n;i++)
	    {
	      int tmp;
	      cin>>tmp;
	      if(tmp==0)
		win++;
	      else if(tmp==1)
		lost++;
	    }
	  data.push_back(node(t,win,lost));
	}
      sort(data.begin(),data.end());
      for(int i=0;i<n;i++)
	cout<<data[i].name<<endl;
    }
  
}