#include <bits/stdc++.h>
using namespace std;
map<string, int> person;
vector<pair<int, string> > points;
int cnt;
bool compare(pair<int, string> a, pair<int, string> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
void update(string name, int p = 0) {
  if (!person[name]) {
    person[name] = ++cnt;
    points.push_back(make_pair(p, name));
  } else
    points[person[name] - 1].first += p;
}
int main() {
  string me;
  int n;
  cin >> me >> n;
  for (int i = 0; i < n; i++) {
    string X, Y, type, temp;
    cin >> X >> type;
    int point;
    if (type == "posted") {
      cin >> temp >> Y >> temp;
      point = 15;
    } else if (type == "commented") {
      cin >> temp >> Y >> temp;
      point = 10;
    } else {
      cin >> Y >> temp;
      point = 5;
    }
    Y = Y.substr(0, Y.length() - 2);
    if (X == me)
      update(Y, point);
    else if (Y == me)
      update(X, point);
    else
      update(X), update(Y);
  }
  sort(points.begin(), points.end(), compare);
  for (int i = 0; i < cnt; i++) cout << points[i].second << endl;
  return 0;
}
