#include <bits/stdc++.h>
using namespace std;
int i, j, n, k;
string A[101], ME;
map<string, int> m;
struct TT {
  string a;
  int pri;
  bool operator<(const TT &g) const {
    if (pri != g.pri)
      return (pri > g.pri);
    else
      return (a < g.a);
  }
} gg[101];
int main() {
  cin >> ME;
  cin >> n;
  getchar();
  for (i = 0; i < n; i++) {
    getline(cin, A[i]);
    string from = "", cmd = "", to = "";
    j = 0;
    while (A[i][j] != ' ') from += A[i][j], j++;
    j++;
    while (A[i][j] != ' ') cmd += A[i][j], j++;
    if (cmd != "likes") {
      j++;
      while (A[i][j] != ' ') j++;
    }
    j++;
    while (A[i][j] != '\'') to += A[i][j], j++;
    if (from == ME || to == ME) {
      if (cmd == "likes") {
        if (from == ME)
          m[to] += 5;
        else
          m[from] += 5;
      } else if (cmd == "commented") {
        if (from == ME)
          m[to] += 10;
        else
          m[from] += 10;
      } else {
        if (from == ME)
          m[to] += 15;
        else
          m[from] += 15;
      }
    } else {
      m[from] += 0;
      m[to] += 0;
    }
  }
  int nn = 0;
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    gg[nn].a = (*it).first, gg[nn].pri = (*it).second;
    nn++;
  }
  sort(gg, gg + nn);
  for (i = 0; i < nn; i++) cout << gg[i].a << endl;
  return 0;
}
