#include <bits/stdc++.h>
using namespace std;
struct node {
  int val;
  string str;
};
bool compare(struct node n1, struct node n2) {
  if (n1.val != n2.val) {
    return n1.val > n2.val;
  } else {
    return (n1.str < n2.str);
  }
}
vector<struct node> v1;
int main() {
  map<string, int> m;
  string s, name;
  getline(cin, s);
  name = s;
  m[name] = 0;
  int n;
  cin >> n;
  getline(cin, s);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    istringstream s1(s);
    string s11;
    s1 >> s11;
    if (m.find(s11) == m.end()) {
      m.insert(make_pair(s11, 0));
    }
    string s2;
    s1 >> s2;
    if (s2 == "posted" || s2 == "commented") {
      bool flag = 1;
      if (s2 == "posted") {
        flag = 0;
      }
      s1 >> s2;
      s1 >> s2;
      int len = s2.length() - 1;
      string s22 = "";
      for (int ii = 0; ii <= len - 2; ii++) {
        s22 += s2[ii];
      }
      if (m.find(s22) == m.end()) {
        m.insert(make_pair(s22, 0));
      }
      if (flag) {
        if (s22 == name) {
          m[s11] += 10;
        }
        if (s11 == name) {
          m[s22] += 10;
        }
      } else {
        if (s22 == name) {
          m[s11] += 15;
        }
        if (s11 == name) {
          m[s22] += 15;
        }
      }
    } else {
      if (s2 == "likes") {
        s1 >> s2;
        string s22 = "";
        int len = s2.length() - 1;
        for (int ii = 0; ii <= len - 2; ii++) {
          s22 += s2[ii];
        }
        if (m.find(s22) == m.end()) {
          m.insert(make_pair(s22, 0));
        }
        if (s22 == name) {
          m[s11] += 5;
        }
        if (s11 == name) {
          m[s22] += 5;
        }
      }
    }
  }
  map<string, int>::iterator it;
  for (it = m.begin(); it != m.end(); it++) {
    if ((*it).first != name) {
      struct node n1;
      n1.val = (*it).second;
      n1.str = (*it).first;
      v1.push_back(n1);
    }
  }
  sort(v1.begin(), v1.end(), compare);
  for (int i = 0; i < v1.size(); i++) {
    cout << v1[i].str << "\r\n";
  }
  return 0;
}
