#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct yku {
  int k, m;
  char t;

  bool operator<(const yku& right) const {
    return k == right.k ? m < right.m : k > right.k;
  }
};

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    yku a[10] = {};
    rep(i, 0, n) {
      cin >> a[i].t;
      rep(j, 0, n - 1) {
        int b;
        cin >> b;
        if(!b) a[i].k++;
        else if(b == 1) a[i].m++;
      }
    }

    sort(a, a + n);
    rep(i, 0, n) cout << a[i].t << endl;
  }
}