#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class team{
public:
	char name;
	int w;
	int l;
	
	bool operator <(const team arg) const{
		if(w == arg.w){
			return l < arg.l;
		}
		return w > arg.w;
	}
};

int main(void){
	int n;
	while(cin >> n && n){
		team t;
		vector<team> v;
		char c;
		int tmp;
		
		for(int j=0;j<n;j++){
			cin >> c;
			t.name = c;
			t.w = 0;
			t.l = 0;
			
			for(int i=0;i<n-1;i++){
				cin >> tmp;
				if(tmp == 0) t.w++;
				if(tmp == 1) t.l++;
			}
			v.push_back(t);
		}
		sort(v.begin(),v.end());
		
		for(int i=0;i<n;i++) cout << v[i].name << endl;
	}
}