#include <bits/stdc++.h>
using namespace std;
map<string, int> ntop;
map<int, string> pton;
vector<pair<int, int> > point;
int getpos(string str) {
  if (ntop.find(str) == ntop.end()) {
    int pos = ((point).size());
    ntop[str] = pos;
    pton[pos] = str;
    point.push_back(make_pair(0, pos));
  }
  return ntop[str];
}
void addpoint(string str, int po) {
  int p = getpos(str);
  point[p].first += po;
}
bool pred(const pair<int, int> &a1, const pair<int, int> &a2) {
  if (a1.first != a2.first) return a1.first > a2.first;
  return pton[a1.second] < pton[a2.second];
}
int main(void) {
  string name;
  int n;
  cin >> name;
  cin >> n;
  for (int i = (0); i < ((n)); ++i) {
    string x, y;
    string action;
    int xpos, ypos;
    cin >> x >> action;
    if (action == "posted") {
      cin >> action >> y >> action;
      y = y.substr(0, ((y).size()) - 2);
      if (x == name) addpoint(y, 15);
      if (y == name) addpoint(x, 15);
    } else if (action == "commented") {
      cin >> action >> y >> action;
      y = y.substr(0, ((y).size()) - 2);
      if (x == name) addpoint(y, 10);
      if (y == name) addpoint(x, 10);
    } else {
      cin >> y >> action;
      y = y.substr(0, ((y).size()) - 2);
      if (x == name) addpoint(y, 5);
      if (y == name) addpoint(x, 5);
    }
    getpos(x);
    getpos(y);
  }
  sort((point).begin(), (point).end(), pred);
  for (int i = (0); i < ((((point).size()))); ++i) {
    const string &n = pton[point[i].second];
    if (n != name) cout << n << endl;
  }
}
