#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  map<pair<string, string>, int> mp;
  string name, name1, name2, tmp;
  cin >> name;
  int n;
  cin >> n;
  set<string> st;
  while (n--) {
    int x = 0;
    cin >> name1 >> tmp;
    if (tmp == "likes") {
      x += 5;
      cin >> name2;
      name2.erase((int)name2.size() - 2, 2);
      cin >> tmp;
      if (name2 < name1) swap(name2, name1);
      mp[{name1, name2}] += x;
      if (name1 != name) st.insert(name1);
      if (name2 != name) st.insert(name2);
    } else {
      if (tmp == "posted")
        x += 15;
      else
        x += 10;
      cin >> tmp;
      cin >> name2;
      name2.erase((int)name2.size() - 2, 2);
      cin >> tmp;
      if (name2 < name1) swap(name2, name1);
      mp[{name1, name2}] += x;
      if (name1 != name) st.insert(name1);
      if (name2 != name) st.insert(name2);
    }
  }
  vector<pair<int, string> > ar;
  for (auto i : st) {
    if (i < name)
      ar.push_back({mp[{i, name}], i});
    else
      ar.push_back({mp[{name, i}], i});
  }
  sort(ar.begin(), ar.end(),
       [](const pair<int, string> &lhs, const pair<int, string> &rhs) {
         if (lhs.first < rhs.first)
           return 0;
         else if (lhs.first > rhs.first)
           return 1;
         else {
           if (lhs.second < rhs.second)
             return 1;
           else
             return 0;
         }
       });
  for (auto i : ar) cout << i.second << '\n';
}
