#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int n, *a, ma, mi, s;
	char *t;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(n, sizeof(int));
		t = (char *)malloc(n*sizeof(char));
		ma = 0;
		mi = 60;
		for(int i = 0; i < n; i++){
			cin >> t[i];
			for(int j = 1; j < n; j++){
				cin >> s;
				if(s == 0){
					a[i] += 3;
				} else if(a[i] == 2){
					a[i] += 1;
				}
			}
			if(a[i] > ma){
				ma = a[i];
			}
			if(a[i] < mi){
				mi = a[i];
			}
		}
		
		for(int i = ma; i >= mi; i--){
			for(int j = 0; j < n; j++){
				if(a[j] == i){
					cout << t[j] << endl;
				}
			}
		}
		
		free(a);
		free(t);
	}
	
	return 0;
}