#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
vector<pair<int, string> > P;
bool cmp(pair<int, string> a, pair<int, string> b) {
  if (a.first != b.first) {
    return a.first > b.first;
  } else {
    return a.second < b.second;
  }
}
string myname, x, y, a, b;
int n;
int main() {
  cin >> myname >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> a;
    if (a == "posted" || a == "commented") {
      cin >> b;
    }
    cin >> y >> b;
    y.erase(y.size() - 2, 2);
    mp[x] += 0;
    mp[y] += 0;
    if (a == "posted") {
      if (y == myname) {
        mp[x] += 15;
      }
      if (x == myname) {
        mp[y] += 15;
      }
    } else if (a == "commented") {
      if (y == myname) {
        mp[x] += 10;
      }
      if (x == myname) {
        mp[y] += 10;
      }
    } else {
      if (y == myname) {
        mp[x] += 5;
      }
      if (x == myname) {
        mp[y] += 5;
      }
    }
  }
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (it->first != myname) {
      P.push_back(make_pair(it->second, it->first));
    }
  }
  sort(P.begin(), P.end(), cmp);
  for (int i = 0; i < P.size(); i++) {
    cout << P[i].second << endl;
  }
  return 0;
}
