#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) && n){
		pair<pair<int, int>, pair<int, char> > t[10];
		
		for (int i = 0; i < n; i++){
			t[i].first.first = t[i].first.second = 0;
			char name;
			scanf(" %c", &name);
			t[i].second.first = i;
			t[i].second.second = name;
			for (int j = 0; j < n - 1; j++){
				int x;
				scanf("%d", &x);
				if (x == 0) t[i].first.first--;
				if (x == 1) t[i].first.second++;
			}
		}
		
		sort(t, t + n);
		
		for (int i = 0; i < n; i++)
			printf("%c\n", t[i].second.second);
	}
}