#include <bits/stdc++.h>
using namespace std;
string convertToString(char* a, int size) {
  string s = a;
  return s;
}
multimap<int, string, greater<int>> invert(map<string, int>& mymap) {
  multimap<int, string, greater<int>> multiMap;
  map<string, int>::iterator it;
  for (it = mymap.begin(); it != mymap.end(); it++) {
    multiMap.insert(make_pair(it->second, it->first));
  }
  return multiMap;
}
int main() {
  string my_name;
  cin >> my_name;
  int n;
  cin >> n;
  map<string, int> m;
  while (n--) {
    vector<string> s;
    string cur;
    cin >> cur;
    s.push_back(cur);
    string r;
    cin >> r;
    s.push_back(r);
    int len;
    if (r == "commented" or r == "posted")
      len = 5;
    else
      len = 4;
    while (s.size() < len) {
      string e;
      cin >> e;
      cur = e;
      s.push_back(cur);
    }
    cur = s[0];
    if (s.size() > 3 and s[1] == "posted") {
      string temp = s[3];
      int k = s[3].length();
      temp = temp.substr(0, k - 2);
      if (cur == my_name) {
        m[temp] += 15;
      } else if (temp == my_name) {
        m[cur] += 15;
      } else {
        if (m.find(cur) == m.end()) m[cur] = 0;
        if (m.find(temp) == m.end()) m[temp] = 0;
      }
    } else if (s.size() > 3 and s[1] == "commented") {
      string temp = s[3];
      int k = s[3].length();
      temp = temp.substr(0, k - 2);
      if (cur == my_name) {
        m[temp] += 10;
      } else if (temp == my_name) {
        m[cur] += 10;
      } else {
        if (m.find(cur) == m.end()) m[cur] = 0;
        if (m.find(temp) == m.end()) m[temp] = 0;
      }
    } else if (s.size() > 2 and s[1] == "likes") {
      string temp = s[2];
      int k = s[2].length();
      temp = temp.substr(0, k - 2);
      if (cur == my_name) {
        m[temp] += 5;
      } else if (temp == my_name) {
        m[cur] += 5;
      } else {
        if (m.find(cur) == m.end()) m[cur] = 0;
        if (m.find(temp) == m.end()) m[temp] = 0;
      }
    }
  }
  multimap<int, string, greater<int>> m1;
  m1 = invert(m);
  for (auto x : m1) {
    if (x.second != my_name) cout << x.second << endl;
  }
}
