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