#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
  map<string, int> m;
  string a, b, c, d, me;
  int n, i, value;
  cin >> me >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (b == "posted") {
      value = 15;
      cin >> b >> b;
    } else if (b == "commented") {
      value = 10;
      cin >> b >> b;
    } else {
      value = 5;
      cin >> b;
    }
    b = b.substr(0, b.length() - 2);
    if (a == me)
      m[b] += value;
    else if (b == me)
      m[a] += value;
    else {
      m[a] += 0;
      m[b] += 0;
    }
    cin >> b;
  }
  pair<int, string> p[105];
  map<string, int>::iterator it;
  n = 0;
  for (it = m.begin(); it != m.end(); it++) {
    p[n++] = make_pair(-(it->second), it->first);
  }
  sort(p, p + n);
  for (i = 0; i < n; i++) cout << p[i].second << endl;
  return 0;
}
