#include <bits/stdc++.h>
using namespace std;
string Name, t, n1, n2, action;
int n, dolly;
map<string, int> f;
vector<pair<int, string> > ans;
int main() {
  cin >> Name;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> n1 >> action;
    if (action == "posted" || action == "commented") cin >> t;
    cin >> n2;
    n2.erase(n2.size() - 2, 2);
    cin >> t;
    if (action == "posted")
      dolly = 15;
    else if (action == "commented")
      dolly = 10;
    else
      dolly = 5;
    if (n1 == Name)
      f[n2] += dolly;
    else
      f[n1];
    if (n2 == Name)
      f[n1] += dolly;
    else
      f[n2];
  }
  for (map<string, int>::iterator it = f.begin(); it != f.end(); it++)
    ans.push_back(make_pair(-1 * it->second, it->first));
  sort(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) cout << ans[i].second << endl;
  return 0;
}
