#include <bits/stdc++.h>
using namespace std;
int N;
string MyName;
map<string, int> names;
set<pair<int, string> > ans;
int main() {
  cin >> MyName;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string X, Y, tmp;
    cin >> X;
    cin >> tmp;
    if (tmp == "posted") {
      int points = 15;
      cin >> tmp;
      cin >> Y;
      Y = Y.substr(0, Y.size() - 2);
      cin >> tmp;
      if (X == MyName)
        names[Y] += points;
      else if (Y == MyName)
        names[X] += points;
    } else if (tmp == "commented") {
      int points = 10;
      cin >> tmp;
      cin >> Y;
      Y = Y.substr(0, Y.size() - 2);
      cin >> tmp;
      if (X == MyName)
        names[Y] += points;
      else if (Y == MyName)
        names[X] += points;
    } else if (tmp == "likes") {
      int points = 5;
      cin >> Y;
      Y = Y.substr(0, Y.size() - 2);
      cin >> tmp;
      if (X == MyName)
        names[Y] += points;
      else if (Y == MyName)
        names[X] += points;
    }
    if (X != MyName and Y != MyName) {
      names[X] += 0;
      names[Y] += 0;
    }
  }
  for (map<string, int>::iterator iter = names.begin(); iter != names.end();
       iter++)
    ans.insert(make_pair(-iter->second, iter->first));
  for (set<pair<int, string> >::iterator iter = ans.begin(); iter != ans.end();
       iter++)
    if (iter->second != MyName) cout << iter->second << endl;
}
