#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long n;
  cin >> n;
  vector<vector<string>> v(n);
  string f;
  getline(cin, f);
  for (long long i = 0; i < n; i++) {
    string ss;
    getline(cin, ss);
    ss += ' ';
    string r = "";
    for (long long j = 0; j < ss.length(); j++) {
      if (ss[j] == ' ') {
        if (r != "") v[i].push_back(r);
        r = "";
      } else {
        if (ss[j] == 39) {
          v[i].push_back(r);
          r = "";
        }
        r += ss[j];
      }
    }
  }
  map<string, long long> name;
  map<string, long long> cnt;
  for (long long i = 0; i < n; i++) {
    if (v[i][1] == "posted") {
      string name1 = v[i][0];
      string name2 = v[i][3];
      name[name1] = 1;
      name[name2] = 1;
      if (name1 == s)
        cnt[name2] += 15;
      else if (name2 == s)
        cnt[name1] += 15;
    } else if (v[i][1] == "commented") {
      string name1 = v[i][0];
      string name2 = v[i][3];
      name[name1] = 1;
      name[name2] = 1;
      if (name1 == s)
        cnt[name2] += 10;
      else if (name2 == s)
        cnt[name1] += 10;
    } else if (v[i][1] == "likes") {
      string name1 = v[i][0];
      string name2 = v[i][2];
      name[name1] = 1;
      name[name2] = 1;
      if (name1 == s)
        cnt[name2] += 5;
      else if (name2 == s)
        cnt[name1] += 5;
    }
  }
  set<pair<long long, string>> s1;
  for (auto it : cnt) s1.insert(make_pair(-it.second, it.first));
  vector<string> ans;
  for (auto it : s1) ans.push_back(it.second);
  for (auto it : name) {
    if (cnt.find(it.first) == cnt.end() && it.first != s)
      ans.push_back(it.first);
  }
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
