#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<string, int>& a, const pair<string, int>& b) {
  if (a.second != b.second) return a.second > b.second;
  return a.first < b.first;
}
int main() {
  string me;
  cin >> me;
  int n;
  cin >> n;
  string x, y;
  string tp;
  unordered_map<string, int> fact;
  for (int i = 0; i < n; i++) {
    cin >> x >> tp;
    if (fact.find(x) == fact.end()) fact[x] = 0;
    if (tp == "commented") {
      cin >> tp >> y >> tp;
      y = y.substr(0, y.size() - 2);
      if (fact.find(y) == fact.end()) fact[y] = 0;
      if (x == me) fact[y] += 10;
      if (y == me) fact[x] += 10;
    } else if (tp == "likes") {
      cin >> y >> tp;
      y = y.substr(0, y.size() - 2);
      if (fact.find(y) == fact.end()) fact[y] = 0;
      if (y == me) fact[x] += 5;
      if (x == me) fact[y] += 5;
    } else {
      cin >> tp >> y >> tp;
      y = y.substr(0, y.size() - 2);
      if (fact.find(y) == fact.end()) fact[y] = 0;
      if (y == me) fact[x] += 15;
      if (x == me) fact[y] += 15;
    }
  }
  vector<pair<string, int>> v;
  for (auto el : fact) {
    if (el.first == me) continue;
    v.push_back({el.first, el.second});
  }
  sort(v.begin(), v.end(), cmp);
  for (auto el : v) {
    cout << el.first << endl;
  }
  return 0;
}
