#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(scanf("%d",&n), n){
    vector<pair<int,pair<int,pair<int,char> > > > v(n);
    REP(i,n){
      char c;
      scanf(" %c ",&c);
      int w=0, l=0;
      REP(j,n-1){
	int a; scanf("%d",&a);
	if(a == 0) w++;
	else if(a==1) l++;
      }
      v[i] = mp(-w, mp(l, mp(i, c)));
    }
    sort(v.begin(), v.end());
    REP(i,n)
      printf("%c\n",v[i].s.s.s);
  }
  return 0;
}