#include<iostream>
#include<vector>

using namespace std;

int result[5];

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	int n;
	while(cin>>n,n){
		vector<char> tn(n);
		vector<int> point(n);
		int max = 0;
		rep(i,n){
			cin>>tn[i];
			int data;
			rep(j,n-1){
				cin>>data;
				if(data==0)point[i]+=3;
				if(data==1)point[i]+=0;
				if(data==2)point[i]+=1;
			}
		if(max<point[i])max = point[i];
		}
		for(int i = max ; 0 <= i ; i --){
			rep(j,n)
			if(i==point[j])cout<<tn[j]<<endl;
		}
	}
}