#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<int, string> &a, const pair<int, string> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
int main() {
  int n;
  string a, b, c, d, e, name;
  map<string, int> v;
  cin >> name >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    if (b == "posted") {
      cin >> c >> d >> e;
      d.erase(d.size() - 2);
      if (a == name || d == name) {
        v[a] += 15;
        v[d] += 15;
      }
      v[a] += 0;
      v[d] += 0;
    } else if (b == "commented") {
      cin >> c >> d >> e;
      d.erase(d.size() - 2);
      if (a == name || d == name) {
        v[a] += 10;
        v[d] += 10;
      }
      v[a] += 0;
      v[d] += 0;
    } else {
      cin >> d >> e;
      d.erase(d.size() - 2);
      if (a == name || d == name) {
        v[a] += 5;
        v[d] += 5;
      }
      v[a] += 0;
      v[d] += 0;
    }
  }
  vector<pair<int, string>> x;
  for (auto c : v) {
    x.push_back(make_pair(c.second, c.first));
  }
  sort(x.begin(), x.end(), comp);
  for (auto c : x) {
    if (c.second != name) {
      cout << c.second << endl;
    }
  }
  return 0;
}
