#include<iostream>
#include<algorithm>
using namespace std;
int n,r;pair<int,char>d[10];
int main(){
	  while (true) {
       cin>>n;
        if (n == 0)break;
        for (int i = 0; i < n; i++) {
            cin >> d[i].second; d[i].first = i;
            for (int j = 0; j < n - 1; j++) {
                scanf("%d", &r);
                if (r == 0) d[i].first -= 100;
                if (r == 1) d[i].first += 10;
            }
        }
        sort(d, d + n);
        for (int i = 0; i < n; i++) cout<<d[i].second<<endl;
    }

	return 0;
}