#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i, m, n) for(int i=(m);i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
typedef pair<Pip, char> Pic;

typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};


int main()
{
  int n;

  while( cin >> n, n ) {
    priority_queue<Pic> q;

    Rep(i, n) {
      char c;
      int win = 0, los = 0;
      cin >> c;
      
      Rep(j, n-1) {
	int a;
	cin >> a;
	if( a == 0 ) win++;
	else if( a == 1 ) los++;
      }

      q.push( Pic(Pip(win, Pii(-los, -i)), c) );
    }

    while( !q.empty() ) {
      cout << q.top().sc << endl;
      q.pop();
    }

  }

}