#include <bits/stdc++.h>
using namespace std;
struct friends {
  string name;
  int fr;
} names[102];
int n, kol;
string s, q, name;
void add(string s, int dr) {
  bool absent = true;
  for (int i = 0; i < kol; i++)
    if (s == names[i].name) {
      names[i].fr += dr;
      absent = false;
      break;
    }
  if (absent) {
    names[kol].name = s;
    names[kol].fr = dr;
    kol++;
  }
}
bool litl(friends a, friends b) {
  for (int i = 0; i < a.name.size(); i++)
    if (a.name[i] > b.name[i])
      return false;
    else if (a.name[i] < b.name[i])
      return true;
  return 0;
}
bool cmp(friends a, friends b) {
  return (a.fr > b.fr || (a.fr == b.fr && a.name < b.name));
}
int main() {
  cin >> name >> n;
  for (int i = 0; i < n; i++) {
    cin >> q >> s;
    if (s == "posted") {
      cin >> s >> s;
      if (q != name && s.substr(0, s.size() - 2) == name)
        add(q, 15);
      else if (q != name)
        add(q, 0);
      add(s.substr(0, s.size() - 2),
          (q == name || s.substr(0, s.size() - 2) == name) ? 15 : 0);
      cin >> s;
    } else if (s == "commented") {
      cin >> s >> s;
      if (q != name && s.substr(0, s.size() - 2) == name)
        add(q, 10);
      else if (q != name)
        add(q, 0);
      add(s.substr(0, s.size() - 2),
          (q == name || s.substr(0, s.size() - 2) == name) ? 10 : 0);
      cin >> s;
    } else {
      cin >> s;
      if (q != name && s.substr(0, s.size() - 2) == name)
        add(q, 5);
      else if (q != name)
        add(q, 0);
      add(s.substr(0, s.size() - 2),
          (q == name || s.substr(0, s.size() - 2) == name) ? 5 : 0);
      cin >> s;
    }
  }
  sort(names, names + kol, cmp);
  for (int i = 0; i < kol; i++) {
    if (names[i].name != name) cout << names[i].name << endl;
  }
  return 0;
}
