#include <bits/stdc++.h>
using namespace std;
map<string, int> score;
int main(void) {
  string me;
  string x, y, cmd, garbage;
  int n;
  cin >> me;
  cin >> n;
  while (n--) {
    cin >> x >> cmd;
    if (cmd[0] != 'l') {
      cin >> garbage;
    }
    cin >> y;
    y = y.substr(0, y.size() - 2);
    cin >> garbage;
    if (x == me || y == me) {
      score[x] -= (cmd[0] == 'p' ? 15 : cmd[0] == 'c' ? 10 : 5);
      score[y] -= (cmd[0] == 'p' ? 15 : cmd[0] == 'c' ? 10 : 5);
    } else {
      score[x] -= 0;
      score[y] -= 0;
    }
  }
  vector<pair<int, string> > p;
  for (map<string, int>::iterator it = score.begin(); it != score.end(); it++) {
    if (it->first == me) {
      continue;
    }
    p.push_back(make_pair(it->second, it->first));
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < p.size(); i++) {
    cout << p[i].second << "\n";
  }
  return 0;
}
