#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> ma;
  vector<pair<int, string> > v;
  int n, i;
  string s, m, a, x, act, y;
  cin >> m >> n;
  while (n--) {
    cin >> x >> act;
    if (act[0] != 'l') cin >> a;
    cin >> y;
    y = y.substr(0, y.size() - 2);
    cin >> a;
    if (x == m || y == m) {
      if (act[0] == 'l') {
        ma[x] = ma[x] + 5;
        ma[y] = ma[y] + 5;
      } else if (act[0] == 'c') {
        ma[x] += 10;
        ma[y] += 10;
      } else {
        ma[x] += 15;
        ma[y] += 15;
      }
    }
    ma[x] += 0;
    ma[y] += 0;
  }
  map<string, int>::iterator it;
  for (it = ma.begin(); it != ma.end(); it++) {
    if ((*it).first != m) v.push_back(make_pair(-(*it).second, (*it).first));
  }
  sort(v.begin(), v.end());
  n = (int)v.size();
  for (i = 0; i < n; i++) cout << v[i].second << endl;
  return 0;
}
