#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<char, int> pii;

bool fanc(pii lhs, pii rhs)
{
	return (lhs.second < rhs.second);
}

int main()
{
	int n;
	
	while (cin >> n, n){
		vector <pii> p(n);
		
		for (int i = 0; i < n; i++){
			char c;
			int num, sum = 0;
			cin >> c;
			
			for (int j = 1; j < n; j++){
				cin >> num;
				sum += num;
			}
			
			p[i] = make_pair(c, sum);
		}
		
		sort(p.begin(), p.end(), fanc);
		
		for (int i = 0; i < n; i++){
			cout << p[i].first << endl;
		}
	}
	
	return (0);
}