#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

class state{
public:
  char t;
  int w,l,id;
  bool operator<(const state & a)const {
    if (w != a.w)return w > a.w;
    if ( l != a.l)return l <a.l;
    return id < a.id;
  }
};

main(){
  int n;
  while(cin>>n && n){
    state data[n];    
    rep(i,n){
      cin>>data[i].t;
      data[i].id=i;
      data[i].w=0;
      data[i].l=0;
      rep(j,n-1){
	int tmp;cin>>tmp;
	if (  tmp == 0)data[i].w++;
	else if ( tmp == 1)data[i].l++;
      }
    }
    sort(data,data+n);
    rep(i,n)cout << data[i].t << endl;
  }
}