#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string me;
  cin >> me >> n;
  set<string> names;
  vector<pair<int, string> > ans;
  map<string, int> m;
  cin.ignore();
  while (n--) {
    string action, first = "", second = "", type = "";
    getline(cin, action);
    int i = 0;
    while (action[i] != ' ') first += action[i], i++;
    i++;
    while (action[i] != ' ') type += action[i], i++;
    int j = action.length() - 1;
    while (action[j] != ' ') j--;
    j -= 3;
    while (action[j] != ' ') second += action[j], j--;
    reverse(second.begin(), second.end());
    if (first == me || second == me) {
      if (second == me) swap(first, second);
      if (type == "likes")
        m[second] += 5;
      else if (type == "commented")
        m[second] += 10;
      else
        m[second] += 15;
      names.insert(second);
    } else
      names.insert(first), names.insert(second);
  }
  for (set<string>::iterator it = names.begin(); it != names.end(); ++it)
    ans.push_back({m[*it], *it});
  sort(ans.begin(), ans.end());
  for (int i = ans.size() - 1; i > -1; i--) {
    vector<string> v;
    v.push_back(ans[i].second);
    i--;
    while (i > -1 && ans[i].first == ans[i + 1].first)
      v.push_back(ans[i].second), i--;
    i++;
    for (int j = v.size() - 1; j > -1; j--) cout << v[j] << endl;
  }
}
