#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T& a) {
  return a * a;
}
template <typename T>
T inline ABS(const T& a) {
  return a < 0 ? -a : a;
}
template <typename T>
T inline MIN(const T& a, const T& b) {
  if (a < b) return a;
  return b;
}
template <typename T>
T inline MAX(const T& a, const T& b) {
  if (a > b) return a;
  return b;
}
using namespace std;
int gr[222][222];
map<string, int> pt;
string name;
bool comp(const string& a, const string& b) {
  if (gr[0][pt[a]] != gr[0][pt[b]]) return gr[0][pt[a]] > gr[0][pt[b]];
  return a < b;
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  string sna, snb, act, trsh;
  int na, nb;
  cin >> name;
  int n;
  cin >> n;
  memset(gr, 0, sizeof(gr));
  int cr = 1;
  pt[name] = 0;
  while (n--) {
    cin >> sna;
    cin >> act;
    if (pt.find(sna) == pt.end()) pt[sna] = cr++;
    na = pt[sna];
    if (act == "posted") {
      cin >> trsh;
      cin >> snb;
      cin >> trsh;
      snb = snb.substr(0, (int)snb.size() - 2);
      if (pt.find(snb) == pt.end()) pt[snb] = cr++;
      nb = pt[snb];
      gr[na][nb] += 15;
      gr[nb][na] += 15;
    } else if (act == "commented") {
      cin >> trsh;
      cin >> snb;
      cin >> trsh;
      snb = snb.substr(0, (int)snb.size() - 2);
      if (pt.find(snb) == pt.end()) pt[snb] = cr++;
      nb = pt[snb];
      gr[na][nb] += 10;
      gr[nb][na] += 10;
    } else {
      cin >> snb;
      cin >> trsh;
      snb = snb.substr(0, (int)snb.size() - 2);
      if (pt.find(snb) == pt.end()) pt[snb] = cr++;
      nb = pt[snb];
      gr[na][nb] += 5;
      gr[nb][na] += 5;
    }
  }
  vector<string> out;
  for (typeof(pt.begin()) xx = pt.begin(); xx != pt.end(); xx++)
    out.push_back(xx->first);
  sort(out.begin(), out.end(), comp);
  for (int i = 0; i < (int)out.size(); ++i)
    if (out[i] != name) cout << out[i] << endl;
  return 0;
}
