#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

struct Data
{
	char c;
	int win;
	int lose;
	Data() : win(0), lose(0) {}
	bool operator< (const Data& d)const{
		return win!=d.win ? win>d.win : lose<d.lose;
	}
};

int main()
{
	int n;
	while(scanf("%d", &n), n){
		Data data[10];
		rep(i, n){
			scanf(" %c", &data[i].c);
			rep(j, n-1){
				int tmp;
				scanf("%d", &tmp);
				if(tmp == 0)
					++data[i].win;
				else if(tmp == 1)
					++data[i].lose;
			}
		}
		sort(data, data+n);
		rep(i, n)
			printf("%c\n", data[i].c);
	}
	return 0;
}