#include <bits/stdc++.h>
using namespace std;
bool myComp(pair<string, int> p1, pair<string, int> p2) {
  if (p1.second > p2.second) {
    return true;
  } else if (p1.second == p2.second && p1.first < p2.first) {
    return true;
  }
  return false;
}
int main() {
  map<string, int> m;
  string user;
  cin >> user;
  int q;
  cin >> q;
  string line;
  string first;
  string second;
  string newSecond;
  string action1;
  string action2;
  string distination;
  cin.ignore();
  while (q--) {
    getline(cin, line);
    stringstream ss(line);
    ss >> first;
    ss >> action1;
    if (action1 != "likes") {
      ss >> action2;
    }
    ss >> second;
    newSecond = second.substr(0, second.find('\''));
    ss >> distination;
    if (first == user) {
      if (action1 == "posted") {
        m[newSecond] += 15;
      } else if (action1 == "commented") {
        m[newSecond] += 10;
      } else {
        m[newSecond] += 5;
      }
    } else if (newSecond == user) {
      if (action1 == "posted") {
        m[first] += 15;
      } else if (action1 == "commented") {
        m[first] += 10;
      } else {
        m[first] += 5;
      }
    } else {
      if (m[first] == 0) {
        m[first] = 0;
      }
      if (m[newSecond] == 0) {
        m[newSecond] = 0;
      }
    }
  }
  vector<pair<string, int>> vec;
  map<string, int>::iterator it;
  for (it = m.begin(); it != m.end(); it++) {
    vec.push_back(make_pair(it->first, it->second));
  }
  sort(vec.begin(), vec.end(), myComp);
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i].first << endl;
  }
  return 0;
}
