#include <bits/stdc++.h>
using namespace std;
bool f(pair<int, string> p1, pair<int, string> p2) {
  return (p1.first > p2.first) ||
         (p1.first == p2.first && p1.second < p2.second);
}
int main() {
  string name, s, s1, s2;
  int n;
  cin >> name >> n;
  getline(cin, s);
  map<string, int> mp, mp2;
  map<string, int>::iterator it;
  for (int i = 0; i < n; ++i) {
    getline(cin, s);
    s += " ";
    stringstream ss(s);
    ss >> s1 >> s;
    if (s == "posted") {
      ss >> s >> s2 >> s;
      s2 = s2.substr(0, s2.length() - 2);
      if (s1 == name || s2 == name) {
        mp[s1] += 15;
        mp[s2] += 15;
      } else {
        mp[s1] += 0;
        mp[s2] += 0;
      }
    } else if (s == "commented") {
      ss >> s >> s2 >> s;
      s2 = s2.substr(0, s2.length() - 2);
      if (s1 == name || s2 == name) {
        mp[s1] += 10;
        mp[s2] += 10;
      } else {
        mp[s1] += 0;
        mp[s2] += 0;
      }
    } else {
      ss >> s2 >> s;
      s2 = s2.substr(0, s2.length() - 2);
      if (s1 == name || s2 == name) {
        mp[s1] += 5;
        mp[s2] += 5;
      } else {
        mp[s1] += 0;
        mp[s2] += 0;
      }
    }
  }
  vector<pair<int, string> > vv;
  for (it = mp.begin(); it != mp.end(); ++it) {
    pair<int, string> p((*it).second, (*it).first);
    vv.push_back(p);
  }
  sort(vv.begin(), vv.end(), f);
  for (int i = 0; i < vv.size(); ++i) {
    if (vv[i].second == name) continue;
    cout << vv[i].second << endl;
  }
  return 0;
}
