// Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char T[10];
		int W[10], L[10], I[10];

		for(int i=0; i<n; i++){
			cin >> T[i];

			W[i] = L[i] = 0;
			for(int j=0; j<n-1; j++){
				int r;
				cin >> r;

				if(r==0){
					W[i]++;
				}
				else if(r==1){
					L[i]++;
				}
			}

			I[i] = i;
		}

		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				if(W[i]<W[j]
				 ||(W[i]==W[j]&&L[i]>L[j])
				 ||(W[i]==W[j]&&L[i]==L[j]&&I[i]>I[j])){
					char c_tmp = T[i];
					T[i] = T[j];
					T[j] = c_tmp;

					int tmp = W[i];
					W[i] = W[j];
					W[j] = tmp;

					tmp = L[i];
					L[i] = L[j];
					L[j] = tmp;

					tmp = I[i];
					I[i] = I[j];
					I[j] = tmp;
				}
			}
		}

		for(int i=0; i<n; i++){
			cout << T[i] << '\n';
		}
	}

	return 0;
}