#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 1100;

string toName[MAXN];
map<string, int> toIdx;
char st[MAXN];
int score[MAXN];

bool cmp(const pair<int, string> &a, const pair<int, string> &b) {
	return a.first != b.first ? a.first > b.first : a.second < b.second;
}

inline int getIdx(string s) {
	if (toIdx.find(s) == toIdx.end()) {
		int size = toIdx.size();
		toIdx[s] = size;
		toName[size] = s;
	}
	return toIdx[s];
}

int main() {
	scanf("%s", st);
	string s = st;
	toIdx[s] = 0;
	toName[0] = s;

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", st);
		string s = st;
		int x = getIdx(s), y;
		scanf("%s", st);
		switch (st[0]) {
			case 'p': 
			   	scanf("%s", st);
				scanf("%s", st);
				s = st;
				y = getIdx(s.substr(0, (int)s.length() - 2));
				if (x == 0 || y == 0) {
					score[x + y] += 15;
				}
				scanf("%s", st);
				break;
			case 'c':
			   	scanf("%s", st);
				scanf("%s", st);
				s = st;
				y = getIdx(s.substr(0, (int)s.length() - 2));
				if (x == 0 || y == 0) {
					score[x + y] += 10;
				}
				scanf("%s", st);
				break;
			case 'l':
				scanf("%s", st);
				s = st;
				y = getIdx(s.substr(0, (int)s.length() - 2));
				if (x == 0 || y == 0) {
					score[x + y] += 5;
				}
				scanf("%s", st);
				break; 
		}
	}
	vector<pair<int, string> > v;
	for (int i = 0; i < (int)toIdx.size(); i++) {
		v.push_back(make_pair(score[i], toName[i]));
	}
	sort(v.begin(), v.end(), cmp);
	for (int i = 0; i < (int)v.size(); i++) {
		if (v[i].second == toName[0]) continue;
		printf("%s\n", v[i].second.c_str());
	}
	return 0;
}
