#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#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()
const int INF = 1<<30;

struct hoge {
  int w, l;
  char c;
  hoge(char c, int w, int l) : c(c), w(w), l(l) {}
};
bool operator<(const hoge &a, const hoge &b) {
  return a.w != b.w ? a.w > b.w : a.l < b.l;
}

int main() {
  int n;
  while(cin >> n, n)  {
    vector<hoge> v;
    REP(j,n) {
      char c;
      cin >> c;
      int a = 0, b = 0;
      REP(i,n-1) {
        int r;
        cin >> r;
        if (r == 0)
          a++;
        else if (r == 1)
          b++;
      }
      v.push_back(hoge(c,a,b));
    }
    sort(ALL(v));
    FOR(it,v)
      cout << it->c << endl;
  }
}