#include <bits/stdc++.h>
using namespace std;
long long solve() {
  string myname;
  cin >> myname;
  long long q;
  cin >> q;
  string trash;
  getline(cin, trash);
  map<string, long long> m;
  while (q--) {
    string str;
    getline(cin, str);
    long long i = 0;
    string s1 = "", s2 = "";
    while (str[i] != ' ') {
      s1 += str[i];
      i++;
    }
    i++;
    if (str[i] == 'p') {
      i += 10;
      while (str[i] != ' ') {
        s2 += str[i];
        i++;
      }
      s2.erase(s2.end() - 1);
      s2.erase(s2.end() - 1);
      if (s1 == myname) {
        m[s2] += 15;
      } else if (s2 == myname) {
        m[s1] += 15;
      } else {
        m[s1];
        m[s2];
      }
    } else if (str[i] == 'c') {
      i += 13;
      while (str[i] != ' ') {
        s2 += str[i];
        i++;
      }
      s2.erase(s2.end() - 1);
      s2.erase(s2.end() - 1);
      if (s1 == myname) {
        m[s2] += 10;
      } else if (s2 == myname) {
        m[s1] += 10;
      } else {
        m[s1];
        m[s2];
      }
    } else {
      i += 6;
      while (str[i] != ' ') {
        s2 += str[i];
        i++;
      }
      s2.erase(s2.end() - 1);
      s2.erase(s2.end() - 1);
      if (s1 == myname) {
        m[s2] += 5;
      } else if (s2 == myname) {
        m[s1] += 5;
      } else {
        m[s1];
        m[s2];
      }
    }
  }
  vector<pair<long long, string>> v;
  for (auto it : m) {
    v.push_back({-it.second, it.first});
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < (long long)v.size(); ++i) {
    cout << v[i].second << "\n";
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
