#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, string> &a, pair<int, string> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
int main() {
  string name;
  cin >> name;
  int n;
  cin >> n;
  map<string, int> m;
  for (int i = 1; i <= n; i++) {
    string name1, name2, op, tem;
    cin >> name1;
    cin >> op;
    if (op == "posted" || op == "commented") cin >> tem;
    cin >> name2;
    cin >> tem;
    name2 = name2.substr(0, name2.length() - 2);
    int val = 5;
    if (op == "posted") val = 15;
    if (op == "commented") val = 10;
    if (name == name1) m[name2] += val;
    if (name == name2) m[name1] += val;
    if (name != name1 && name != name2) {
      m[name1] += 0;
      m[name2] += 0;
    }
  }
  vector<pair<int, string>> v;
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    v.push_back(make_pair(it->second, it->first));
  }
  sort(v.begin(), v.end(), compare);
  int s = v.size();
  for (int i = 0; i < s; i++) cout << v[i].second << "\n";
  return 0;
}
