#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> v;
  string g;
  cin >> g;
  int n;
  cin >> n;
  int k = 0;
  map<string, int> m;
  string a, b, c, d, e, f = "";
  for (int i = 1; i <= n; i++) {
    f = "";
    cin >> a;
    cin >> b;
    if (b == "posted" || b == "commented") {
      cin >> c;
    }
    cin >> d;
    for (int j = 0; j < d.size() - 2; j++) {
      f = f + d[j];
    }
    cin >> e;
    if (a == g || f == g) {
      if (a == g) {
        if (m.find(f) == m.end()) {
          m[f] = 0;
        }
      }
      if (f == g) {
        if (m.find(a) == m.end()) {
          m[a] = 0;
        }
      }
      if (a == g && b == "posted") {
        m[f] = m[f] + 15;
      }
      if (a == g && b == "commented") {
        m[f] = m[f] + 10;
      }
      if (a == g && b == "likes") {
        m[f] = m[f] + 5;
      }
      if (f == g && b == "posted") {
        m[a] = m[a] + 15;
      }
      if (f == g && b == "commented") {
        m[a] = m[a] + 10;
      }
      if (f == g && b == "likes") {
        m[a] = m[a] + 5;
      }
    } else {
      if (m.find(f) == m.end()) {
        m[f] = 0;
      }
      if (m.find(a) == m.end()) {
        m[a] = 0;
      }
    }
  }
  vector<pair<int, string>> vv;
  int l = 0;
  for (auto x : m) {
    vv.push_back(make_pair(((-1) * x.second), x.first));
  }
  sort(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); i++) {
    cout << vv[i].second << "\n";
  }
  return 0;
}
