#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int n;
	
	while(true){
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		string str[100];
		
		int score[100];
		
		for(int i = 0; i < n; i++){
			cin >> str[i];
			score[i] = 0;
			for(int j = 0; j < n - 1; j++){
				int hoge;
				cin >> hoge;
				if(hoge == 0){
					score[i] += 100;
				}else if(hoge == 1){
					score[i] -= 1;
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n - 1; j++){
				if(score[j] < score[j + 1]){
					swap(score[j], score[j + 1]);
					swap(str[j], str[j + 1]);
				}
			}
		}
		
		for(int i = 0; i < n; i++){
			cout << str[i] << endl;
		}
		
	}
	
	return 0;
}