#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s2 == "posted") {
      cin >> s2 >> s2;
      s2 = s2.substr(0, s2.size() - 2);
      if (s1 == s && s2 != s) {
        mp[s2] += 15;
      }
      if (s1 != s && s2 == s) {
        mp[s1] += 15;
      }
      if (s1 != s && s2 != s) {
        mp[s1] += 0;
        mp[s2] += 0;
      }
      cin >> s2;
      continue;
    }
    if (s2 == "commented") {
      cin >> s2 >> s2;
      s2 = s2.substr(0, s2.size() - 2);
      if (s1 == s && s2 != s) {
        mp[s2] += 10;
      }
      if (s1 != s && s2 == s) {
        mp[s1] += 10;
      }
      if (s1 != s && s2 != s) {
        mp[s1] += 0;
        mp[s2] += 0;
      }
      cin >> s2;
      continue;
    }
    if (s2 == "likes") {
      cin >> s2;
      s2 = s2.substr(0, s2.size() - 2);
      if (s1 == s && s2 != s) {
        mp[s2] += 5;
      }
      if (s1 != s && s2 == s) {
        mp[s1] += 5;
      }
      if (s1 != s && s2 != s) {
        mp[s1] += 0;
        mp[s2] += 0;
      }
      cin >> s2;
      continue;
    }
  }
  pair<int, string> p[111];
  int q = 0;
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    p[q] = make_pair(-(*it).second, (*it).first);
    q++;
  }
  sort(p + 0, p + q);
  for (int i = 0; i < q; i++) {
    cout << p[i].second << endl;
  }
  return 0;
}
