#include <bits/stdc++.h>
using namespace std;
int count(string action) {
  switch (action[0]) {
    case 'p':
      return 15;
    case 'c':
      return 10;
    case 'l':
      return 5;
  }
  return 0;
}
struct my_pair {
  int i;
  string s;
  bool operator<(const my_pair& op) const {
    if (i < op.i) {
      return true;
    }
    if (i > op.i) {
      return false;
    }
    if (i == op.i) {
      return s > op.s;
    }
  }
  bool operator>(const my_pair& op) const { return op < *this; }
};
int main() {
  string name_hero;
  cin >> name_hero;
  int count_actions;
  cin >> count_actions;
  vector<string> friends;
  vector<int> coefficient_friendship;
  for (int i = 0; i < count_actions; ++i) {
    string name1, name2, action, buffer;
    cin >> name1 >> action;
    if ((action == "posted") || (action == "commented")) {
      cin >> buffer;
    }
    cin >> name2 >> buffer;
    name2 = name2.substr(0, name2.size() - 2);
    if (name1 != name_hero) {
      vector<string>::iterator it = find(friends.begin(), friends.end(), name1);
      if (it == friends.end()) {
        friends.push_back(name1);
        coefficient_friendship.push_back(name2 == name_hero ? count(action)
                                                            : 0);
      } else {
        coefficient_friendship[it - friends.begin()] +=
            name2 == name_hero ? count(action) : 0;
      }
    }
    if (name2 != name_hero) {
      vector<string>::iterator it = find(friends.begin(), friends.end(), name2);
      if (it == friends.end()) {
        friends.push_back(name2);
        coefficient_friendship.push_back(name1 == name_hero ? count(action)
                                                            : 0);
      } else {
        coefficient_friendship[it - friends.begin()] +=
            name1 == name_hero ? count(action) : 0;
      }
    }
  }
  vector<my_pair> result(friends.size());
  for (int i = 0; i < friends.size(); ++i) {
    result[i].i = coefficient_friendship[i];
    result[i].s = friends[i];
  }
  sort(result.begin(), result.end());
  for (int i = 0; i < result.size(); ++i) {
    cout << result[result.size() - 1 - i].s << "\n";
  }
  return 0;
}
