#include <bits/stdc++.h>
using namespace std;
string change(string s) {
  string tmp = "";
  for (int i = 0; i < s.size(); i++) {
    string cur = "";
    cur += s[i];
    cur += s[i + 1];
    if (cur == "'s") break;
    tmp += s[i];
  }
  return tmp;
}
bool cmp(pair<string, int> p1, pair<string, int> p2) {
  if (p1.second != p2.second) return p1.second > p2.second;
  return p1.first < p2.first;
}
int main() {
  string me;
  cin >> me;
  int n;
  cin >> n;
  cin.ignore();
  string s;
  vector<pair<string, int> > ans;
  map<string, int> cnt;
  while (n--) {
    getline(cin, s);
    vector<string> tmp;
    string cur = "";
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == ' ') {
        tmp.push_back(cur);
        cur = "";
        continue;
      }
      cur += s[i];
    }
    tmp.push_back(cur);
    if (tmp[1] == "posted" || tmp[1] == "commented") {
      if (cnt.find(tmp[0]) == cnt.end()) cnt[tmp[0]] = 0;
      string str = change(tmp[3]);
      if (cnt.find(str) == cnt.end()) cnt[str] = 0;
      if (tmp[1] == "posted") {
        if (tmp[0] == me) cnt[str] += 15;
        if (str == me) cnt[tmp[0]] += 15;
      }
      if (tmp[1] == "commented") {
        if (tmp[0] == me) cnt[str] += 10;
        if (str == me) cnt[tmp[0]] += 10;
      }
    } else if (tmp[1] == "likes") {
      if (cnt.find(tmp[0]) == cnt.end()) cnt[tmp[0]] = 0;
      string str = change(tmp[2]);
      if (cnt.find(str) == cnt.end()) cnt[str] = 0;
      if (tmp[0] == me) cnt[str] += 5;
      if (str == me) cnt[tmp[0]] += 5;
    }
  }
  map<string, int>::iterator it;
  for (it = cnt.begin(); it != cnt.end(); it++)
    ans.push_back(make_pair(it->first, it->second));
  sort(ans.begin(), ans.end(), cmp);
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i].first == me) continue;
    cout << ans[i].first << "\n";
  }
  return 0;
}
