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

bool myComparison(pair<string, int> a, pair<string, int> b) {
	if (a.second > b.second) return true;
	else if (a.second < b.second) return false;
	else return (a.first < b.first);
}

int main() {

	vector <pair<string, int>> clasament;
	string echipa1, echipa2;
	int scor1, scor2;

	for (int i = 0; i < 6; i++) {
		getline(cin, echipa1, ' ');
		getline(cin, echipa2, ' ');
		transform(echipa1.begin(), echipa1.end(), echipa1.begin(), ::tolower);
		transform(echipa2.begin(), echipa2.end(), echipa2.begin(), ::tolower);
		cin >> scor1 >> scor2;
		cin.get();

		bool flag1 = false;
		for (unsigned int j = 0; j < clasament.size(); j++) {
			if (clasament[j].first == echipa1) {
				flag1 = true;
				break;
			}
		}

		if (flag1 == false) {
			clasament.push_back(make_pair(echipa1, 0));
		}

		bool flag2 = false;
		for (unsigned int j = 0; j < clasament.size(); j++) {
			if (clasament[j].first == echipa2) {
				flag2 = true;
				break;
			}
		}

		if (flag2 == false) {
			clasament.push_back(make_pair(echipa2, 0));
		}

		for (unsigned int j = 0; j < clasament.size(); j++)
			if (clasament[j].first == echipa1) {
				if (scor1 > scor2) clasament[j].second += 3;
				else if (scor1 == scor2) clasament[j].second++;
			}

		for (unsigned int j = 0; j < clasament.size(); j++)
			if (clasament[j].first == echipa2) {
				if (scor1 < scor2) clasament[j].second += 3;
				else if (scor1 == scor2) clasament[j].second++;
			}
	}

	sort(clasament.begin(), clasament.end(), myComparison);


	for (unsigned int i = 0; i < clasament.size(); i++)
		clasament[i].first[0] = toupper(clasament[i].first[0]);


	for (unsigned int i = 0; i < clasament.size(); i++)
		cout << clasament[i].first << endl;
	

	return 0;
}