#include <bits/stdc++.h>
using namespace std;
int n;
const int INF = 1 << 29;
string me, fr, sec, act, tmp;
map<string, int> mp;
vector<pair<int, string> > v;
int main() {
  cin >> me >> n;
  while (n--) {
    cin >> fr >> act;
    if (act[0] != 'l') cin >> tmp;
    cin >> sec >> tmp;
    sec.erase(sec.size() - 2, 2);
    if (act[0] == 'p') {
      if (me == fr)
        mp[sec] += 15;
      else if (me == sec)
        mp[fr] += 15;
    } else if (act[0] == 'c') {
      if (me == fr)
        mp[sec] += 10;
      else if (me == sec)
        mp[fr] += 10;
    } else {
      if (me == fr)
        mp[sec] += 5;
      else if (me == sec)
        mp[fr] += 5;
    }
    if (fr != me) mp[fr] += 0;
    if (sec != me) mp[sec] += 0;
  }
  for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    v.push_back(make_pair(INF - it->second, it->first));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i].second != me) cout << v[i].second << endl;
  }
}
