#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> m;
  vector<pair<int, string>> v;
  string name, s;
  set<string> c;
  int n;
  cin >> name;
  cin >> n;
  getline(cin, s);
  for (int i = 1; i <= n; i++) {
    getline(cin, s);
    string l, r;
    l.clear();
    r.clear();
    int j = 0;
    while (s[j] != ' ') {
      l = l + s[j];
      j++;
    }
    j = s.size() - 8;
    while (s[j] != ' ') {
      r = s[j] + r;
      j--;
    }
    if (l == name || r == name) {
      if (s[l.size() + 1] == 'p') {
        m[l] += 15;
        m[r] += 15;
      }
      if (s[l.size() + 1] == 'c') {
        m[l] += 10;
        m[r] += 10;
      }
      if (s[l.size() + 1] == 'l') {
        m[l] += 5;
        m[r] += 5;
      }
    } else {
      m[l];
      m[r];
    }
    c.insert(l);
    c.insert(r);
  }
  set<string>::iterator it = c.begin();
  for (; it != c.end(); it++) {
    if (*it != name) {
      v.push_back(make_pair(m[*it], *it));
    }
  }
  for (int i = 0; i < v.size() - 1; i++) {
    for (int j = 0; j < v.size() - 1; j++) {
      if (v[j].first < v[j + 1].first) {
        swap(v[j], v[j + 1]);
      }
    }
  }
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].second << endl;
  }
  return 0;
}
