#include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)  
	bool cmp(const pair<int,char> &a,const pair<int,char> &b){  
		return a.first > b.first; 
}

int main(void){ 
	int n;   
	while(cin >> n,n){       
		vector< pair<int,char> > data(n);      
		rep(i,n){          
			int sum = 0;     
			cin >> data[i].second;   
			rep(j,n-1){              
				int t;                
				cin >> t;              
				sum += (t==0?10:t==2?1:0);  
			} 
			data[i].first = sum; 
		}   
		stable_sort(data.begin(),data.end(),cmp);  
		rep(i,n){         
			cout << data[i].second << endl;       
		}
	}
	return 0;
} 