#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<char> t(n);
    vector<int> win(n, 0), lose(n, 0), ord(n);
    iota(ord.begin(), ord.end(), 0);
    for (int i = 0; i < n; i++) {
      cin >> t[i];
      for (int j = 0; j < n - 1; j++) {
        int r;
        cin >> r;
        if (r == 0) win[i]++;
        else if (r == 1) lose[i]++;
      }
    }
    sort(ord.begin(), ord.end(), [&](int a, int b) {
      if (win[a] != win[b]) return win[a] > win[b];
      return lose[a] < lose[b];
    });
    for (int i = 0; i < n; i++) {
      cout << t[ord[i]] << endl;
    }
  }

  return 0;
}
