#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
  int n = 1;
  while(n != 0){
    cin >> n;
    if(n == 0)break;
    vector<pair<int,pair<int,pair<int,char>>>>v(n);
    rep(i,n){
      char c;
      cin >> c;
      int cnt1 = 0,cnt2 = 0;
      rep(j,n - 1){
        int tmp;
        cin >> tmp;
        if(tmp == 0)cnt1--;
        if(tmp == 1)cnt2++;
      }
      v[i] = {cnt1,{cnt2,{i,c}}};
    }
    sort(v.begin(),v.end());
    rep(i,n)cout << v[i].second.second.second << endl;
  }
  return 0;
}
