#include <bits/stdc++.h>

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

struct Score {
    int win;
    int lose;
    char id;
    Score(char id, int win, int lose) : id(id), win(win), lose(lose) {}
};
bool operator<(const Score& a, const Score& b){
    return a.win == b.win ? a.lose < b.lose : a.win > b.win;
}

int main()
{
    int n;
    while (n = in()){
        vector<Score> scores;
        rep(i, n){
            char id[8];
            int bucket[3] = {};
            scanf("%s", id);
            rep(j, n - 1) bucket[in()]++;
            scores.push_back(Score(id[0], bucket[0], bucket[1]));
        }
        sort(scores.begin(), scores.end());
        eachv(scores, i) printf("%c\n", scores[i].id);
    }
    return (0);
}