#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef pair<string, int[3]> term;

bool srt(term a, term b){
	return  a.second[0] > b.second[0] || (a.second[0] == b.second[0] && a.second[1] < b.second[1]);
}

int main(){
	int n;
	int num;
	while(cin >> n, n){
		term result[10];

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

			for(int j=0; j < n-1; j++){
				cin >> num;
				result[i].second[num]++;
			}
		}
		stable_sort(result, result+n, srt);
		for(int i=0; i < n; i++){
			cout << result[i].first << endl;
		}

	}
}