#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

struct PROFILE {
    char name[5];
    int win_num;
    int lose_num;
};

bool operator<(const PROFILE& left, const PROFILE& right)
{
    return left.win_num > right.win_num;
}

int main(void)
{
    struct PROFILE team[10];
    int n;
    
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < 10; i++){
           team[i].win_num = team[i].lose_num = 0;
        }
        
        int tmp;
        for (int i = 0; i < n; i++){
            scanf("%s", team[i].name);
            for (int j = 0; j < (n - 1); j++){
                scanf("%d", &tmp);
                if (tmp == 0) team[i].win_num++;
                else if (tmp == 1) team[i].lose_num++;
            }
        }
        
        sort(team, team + n);
        
        for (int i = 0; i < n; i++){
            printf("%c\n", team[i].name[0]);
        }
    }
    
    return (0);
}