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

int main()
{
  int n;
  while (cin >> n, n){
    pair<pair<int, int>, char> ppiic[11];
    for (int i = 0; i < n; i++){
      char c;
      ppiic[i].first = make_pair(0, 0);
      cin >> c;
      ppiic[i].second = c;
      for (int j = 0; j < n - 1; j++){
        int num;
        cin >> num;
        if (num == 0) ppiic[i].first.first++;
        else if (num == 1) ppiic[i].first.second--;;
      }
    }
    stable_sort(ppiic, ppiic + n);
    reverse(ppiic, ppiic + n);

    for (int i  = 0; i < n; i++){
      cout << ppiic[i].second << '\n';
    }
  }
}