#include <iostream>
using namespace std;

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    pair<pair<int,int>,pair<int,char> > t[n];

    for(int i = 0; i < n; i++){
      t[i].second.first = i;
      cin >> t[i].second.second;

      t[i].first.first = 0;
      t[i].first.second = 0;

      for(int j = 0; j < n - 1; j++){
        int x;
        cin >> x;

        if(x == 0) t[i].first.first--;
        else if(x == 1) t[i].first.second++;
      }
    }

    sort(t, t + n);

    for(int i = 0; i < n; i++){
      cout << t[i].second.second << endl;
    }
  }
}