#include <bits/stdc++.h>

using namespace std;

const int INF = 10000000;

class TeamInfo {
public:
	int id;
	char name;
	int win, lost;
};

TeamInfo TeamData[10];
int N;

void init() {
	for (int i = 0; i < 10; i++) {
		TeamData[i].name = '\0';
		TeamData[i].win = TeamData[i].lost = 0;
	}
}

bool cmp(const TeamInfo &t1, const TeamInfo &t2) {
	if (t1.win == t2.win && t1.lost == t2.lost) {
		return t1.id < t2.id;
	}
	if (t1.win == t2.win) {
		return t1.lost < t2.lost;
	}
	return t1.win > t2.win;
}

int main(){
	int num, size;
	string str;

	while (cin >> N, N) {
		getchar();
		init();
		for (int i = 0; i < N; i++) {
			TeamData[i].id = i;
			str = "";
			getline(cin, str);
			//cout << "str:" << str.size() << " " << str << endl;
			TeamData[i].name = str[0];
			//cout << TeamData[i].name << " ";
			size = str.size();
			for (int j = 2; j < size; j += 2) {
				num = str[j] - '0';
				//cout << num << " ";
				if (num == 0) {
					++TeamData[i].win;
				}
				else if (num == 1) {
					++TeamData[i].lost;
				}
			}
		}
		sort(TeamData, TeamData + N, cmp);
		for (int i = 0; i < N; i++) {
			cout << TeamData[i].name << endl;
		}
	}

	return 0;
}
