#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string own, fr, op, a1;
  cin >> own;
  int t;
  map<string, int> mp;
  vector<pair<int, string>> v;
  cin >> t;
  while (t--) {
    cin >> fr >> op;
    if (op.compare("posted") == 0) {
      cin >> a1 >> a1;
      if (fr.compare(own) == 0 ||
          a1.substr(0, a1.length() - 2).compare(own) == 0) {
        mp[fr] += 15;
        mp[a1.substr(0, a1.length() - 2)] += 15;
      } else {
        mp[fr] += 0;
        mp[a1.substr(0, a1.length() - 2)] += 0;
      }
      cin >> a1;
    } else if (op.compare("commented") == 0) {
      cin >> a1 >> a1;
      if (fr.compare(own) == 0 ||
          a1.substr(0, a1.length() - 2).compare(own) == 0) {
        mp[fr] += 10;
        mp[a1.substr(0, a1.length() - 2)] += 10;
      } else {
        mp[fr] += 0;
        mp[a1.substr(0, a1.length() - 2)] += 0;
      }
      cin >> a1;
    } else if (op.compare("likes") == 0) {
      cin >> a1;
      if (fr.compare(own) == 0 ||
          a1.substr(0, a1.length() - 2).compare(own) == 0) {
        mp[fr] += 5;
        mp[a1.substr(0, a1.length() - 2)] += 5;
      } else {
        mp[fr] += 0;
        mp[a1.substr(0, a1.length() - 2)] += 0;
      }
      cin >> a1;
    }
  }
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    v.push_back(make_pair(-it->second, it->first));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i].second != own) cout << v[i].second << endl;
  }
  return 0;
}
