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

struct team {
  char name;
  int win, lose;
};

bool cmp(const team& a, const team& b) {
  if (a.win != b.win) return a.win > b.win;
  return a.lose < b.lose;
}

int main() {
  int n;
  while (cin >> n, n) {
    char t;
    int r;
    vector<team> v(n);
    for (int i = 0; i < n; i++) {
      cin >> t;
      v[i].name = t;
      for (int j = 0; j < n - 1; j++) {
        cin >> r;
        if (r == 0) v[i].win++;
        else if (r == 1) v[i].lose++;
      }
    }
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < n; i++) {
      cout << v[i].name << "\n";
    }
  }
}

