#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
  string name;
  cin >> name;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string p1;
    cin >> p1;
    string task, buf;
    cin >> task;
    if (task == "posted" or task == "commented") cin >> buf;
    string p2;
    cin >> p2;
    p2 = p2.substr(0, p2.size() - 2);
    int points = 5;
    if (task == "posted") points = 15;
    if (task == "commented") points = 10;
    if (p1 == name)
      m[p2] += points;
    else if (p2 == name)
      m[p1] += points;
    else {
      m[p1];
      m[p2];
    }
    cin >> buf;
  }
  set<pair<long long int, string> > s;
  for (auto it : m) s.insert({-it.second, it.first});
  for (auto it : s) cout << it.second << endl;
  return 0;
}
