#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, long> names;
  string ccs, myname;
  cin >> myname;
  names[myname] = 100000;
  long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ccs;
    string cc;
    cin >> cc;
    if (cc == "posted") {
      cin >> cc;
      cin >> cc;
      names[ccs] += 0;
      names[cc.substr(0, cc.length() - 2)] += 0;
      if (cc.substr(0, cc.length() - 2) == myname || ccs == myname) {
        names[ccs] += 15;
        names[cc.substr(0, cc.length() - 2)] += 15;
      }
      cin >> cc;
    } else if (cc == "commented") {
      cin >> cc;
      cin >> cc;
      names[ccs] += 0;
      names[cc.substr(0, cc.length() - 2)] += 0;
      if (cc.substr(0, cc.length() - 2) == myname || ccs == myname) {
        names[ccs] += 10;
        names[cc.substr(0, cc.length() - 2)] += 10;
      }
      cin >> cc;
    } else {
      cin >> cc;
      names[ccs] += 0;
      names[cc.substr(0, cc.length() - 2)] += 0;
      if (cc.substr(0, cc.length() - 2) == myname || ccs == myname) {
        names[ccs] += 5;
        names[cc.substr(0, cc.length() - 2)] += 5;
      }
      cin >> cc;
    }
  }
  vector<long> scores;
  for (map<string, long>::iterator it = names.begin(); it != names.end();
       it++) {
    if (myname != it->first) scores.push_back(it->second);
  }
  sort(scores.begin(), scores.end());
  for (int i = 0; i < scores.size(); i++) {
    if (scores[scores.size() - i - 1] == scores[scores.size() - i]) continue;
    vector<string> last;
    for (map<string, long>::iterator it = names.begin(); it != names.end();
         it++)
      if (it->second == scores[scores.size() - i - 1])
        last.push_back(it->first);
    sort(last.begin(), last.end());
    for (int j = 0; j < last.size(); j++) {
      if (i == scores.size() - 1 && j == last.size() - 1)
        cout << last[j];
      else
        cout << last[j] << endl;
    }
  }
  return 0;
}
