#include<iostream>
using namespace std;
const int MAX=10;
int main(){
	char team[MAX+1];
	int n,score;
	int sum[MAX+1];
	while(cin >> n){
		if(n==0) break;
		for(int i=0; i<n; i++) sum[i]=0;
		
		for(int k=0; k<n; k++){
			cin >> team[k];
			for(int i=0; i<n-1; i++){
				cin >> score;
				if(score==0) sum[k]+=2;
				if(score==2) sum[k]+=1;
			}
			cout << team[k] << " " << sum[k] << endl;
		}
		int count=0;
		while(count!=n){
			int max_score=sum[0],winer=0;
			for(int i=0; i<n; i++){
				if(max_score < sum[i]){
					max_score = sum[i];
					winer=i;
				}
			}
			cout << team[winer] << endl;
			sum[winer]=-1;
			count++;
		}
	}
	return 0;
}