#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

#define WIN 1000
#define LOSE -1

struct Bigger {
    bool operator()(pair<int, char>a, pair<int, char>b) {
        return a.first > b.first;
    }
};

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector< pair<int, char> > team(n);
        for (int i = 0; i < n; i++) {
            char t; cin >> t;
            int r;
            int point = 0;
            for (int j = 0; j < n-1; j++) {
                cin >> r;
                if (r == 0) point += WIN;
                if (r == 1) point += LOSE;
            }
            team[i].first = point;
            team[i].second = t;
        }
        stable_sort(team.begin(), team.end(), Bigger());
        for (int i = 0; i < n; i++) {
            cout << team[i].second << endl;
        }
    }
    return 0;
}