#include<stdio.h>
int main()
{
	int i, n, ruito[12][11] = { 0 }, debu[12][4] = { 0 }, masatoy, k, j, temp;
	char str[20];
	char baka[2];
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%s", &str[i]);
		for (k = 1; k <= n - 1; k++) {
			scanf("%d", &ruito[i][k]);
		}
	}
	for (i = 1; i <= n; i++) {
		for (k = 1; k <= n - 1; k++) {
			if (ruito[i][k] == 0) {
				debu[i][1]++;
			}
			else if (ruito[i][k] == 1) {
				debu[i][2]++;
			}
			else {
				debu[i][3]++;
			}
		}
	}
	for (i = 1; i < n; i++) {
		for (j = n; j > i; j--) {
			if (debu[j][1] > debu[j-1][1]) {
				temp = debu[j][1];
				debu[j][1] = debu[j - 1][1];
				debu[j - 1][1] = temp;
				baka[1] = str[j];
				str[j] = str[j - 1];
				str[j - 1] = baka[1];
			}
		}
	}
	for (i = 1; i < n; i++) {
		for (j = n; j > i; j--) {
			if (debu[j][1] == debu[j - 1][1]) {
				if (debu[j][2] < debu[j - 1][2]) {
					temp = debu[j][1];
					debu[j][1] = debu[j - 1][1];
					debu[j - 1][1] = temp;
					baka[1] = str[j];
					str[j] = str[j - 1];
					str[j - 1] = baka[1];
				}
			}
		}
	}
	for (i = 1; i <= n; i++) {
		printf("%c\n", str[i]);
	}
	return 0;
}