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

int main() {
    int n;
    while (cin >> n, n) {
        vector<char> name(n);
        vector<int> cnt_w(n), cnt_l(n);
        for (int i = 0; i < n; i++) {
            cin >> name[i];
            for (int j = 0; j < n - 1; j++) {
                int r; cin >> r;
                if (r == 0) cnt_w[i]++;
                if (r == 1) cnt_l[i]++;
            }
        }
        vector<vector<int>> res(n);
        for (int i = 0; i < n; i++) res[cnt_w[i]].emplace_back(i);
        for (int w = 0; w < n; w++) {
            sort(res[w].begin(), res[w].end(), [&](int i, int j) {
                if (cnt_l[i] == cnt_l[j]) return i < j;
                else return cnt_l[i] < cnt_l[j];
            });
        }
        for (int w = n - 1; w >= 0; w--){
            for (int idx: res[w]) cout << (char)name[idx] << endl;
        }
    }
    return 0;
}
