#include <bits/stdc++.h>
using namespace std;
map<string, int> score;
set<string> nameList;
string me, temp, name[1000];
tuple<int, string> careList[1000];
int n, cnt = 1;
void check_and_add(string temp) {
  if (nameList.find(temp) == nameList.end()) {
    nameList.insert(temp);
    name[cnt++] = temp;
  }
}
int main(int argc, char const* argv[]) {
  regex pattern("(\\w+) (\\w+ ?\\w+) (\\w+)'s ((wall)|(post))");
  cmatch result;
  cin >> me >> n;
  getline(cin, temp);
  for (int i = 1; i <= n; i++) {
    getline(cin, temp);
    if (regex_match(temp.c_str(), result, pattern)) {
      check_and_add(result[1]);
      check_and_add(result[3]);
      if (result[3] == me) {
        if (result[2] == "posted on") score[result[1]] += 15;
        if (result[2] == "commented on") score[result[1]] += 10;
        if (result[2] == "likes") score[result[1]] += 5;
      }
      if (result[1] == me) {
        if (result[2] == "posted on") score[result[3]] += 15;
        if (result[2] == "commented on") score[result[3]] += 10;
        if (result[2] == "likes") score[result[3]] += 5;
      }
    } else {
      printf("failed\n");
    }
  }
  for (int i = 1; i < cnt; i++)
    careList[i] = tuple<int, string>(-score[name[i]], name[i]);
  sort(careList + 1, careList + cnt);
  for (int i = 1; i < cnt; i++)
    if (get<1>(careList[i]) != me) cout << get<1>(careList[i]) << endl;
  return 0;
}
