#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define S second
#define F first
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<string,PP> SPP;
bool cmp(const SPP &p,const SPP &q){
  if(p.S.F.F != q.S.F.F)return p.S.F.F > q.S.F.F;
  else if(p.S.F.S != q.S.F.S)return p.S.F.S < q.S.F.S;
  else return p.S.S.S < q.S.S.S;
}


int main(){
  int n;
  while(true){
    cin >> n;
    if(n == 0)break;
    vector<SPP> info; string s;
    for(int i=0;i<n;i++){
      cin >> s;
      info.push_back(SPP(s,PP(P(0,0),P(0,i))));
      for(int j=0;j<n-1;j++)
	{ int a;
	  cin >> a;
	  if(a == 0)info[i].S.F.F++;
	  else if(a == 1)info[i].S.F.S++;
	  else info[i].S.S.F++;
	}
    }
     
      sort(info.begin(),info.end(),cmp);
     
      for(int i=0;i<info.size();i++){
		cout << info[i].F << endl;
      }
    

  }
  return 0;
}