#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct R{
	vector<int> v;
	string s;
	bool operator<(const R &a)const{
		return v<a.v;
	}
};
int main(){
	int n,t; vector<int> v(3); string s; R r;
	while(cin>>n,n){
		vector<R> vr;
		rep(i,n){
			cin>>s;
			v[0]=0,v[1]=0,v[2]=i;
			rep(j,n-1)cin>>t,t?t==1?v[1]++:0:v[0]--;
			r.v=v,r.s=s; vr.push_back(r);
		}
		sort(vr.begin(),vr.end());
		rep(i,n)cout<<vr[i].s<<endl;
	}
	return 0;
}