#include <bits/stdc++.h>
using namespace std;
map<string, int> M;
int p, n, len;
string myname, a, b;
char str[105];
struct ppl {
  int point;
  string so;
  bool operator<(const ppl &k) const {
    return point > k.point || (point == k.point && so < k.so);
  }
};
ppl s[105];
int main() {
  cin >> myname;
  scanf("%d\n", &n);
  for (int q = (1); q <= (n); q++) {
    cin.getline(str, 105);
    len = strlen(str);
    a = b = "";
    int pos, pt;
    for (int i = (0); i <= (len - 1); i++) {
      if (str[i] == ' ') {
        pos = i + 1;
        break;
      }
      a += str[i];
    }
    if (str[pos] == 'p') pt = 15;
    if (str[pos] == 'c') pt = 10;
    if (str[pos] == 'l') pt = 5;
    int trig = -1, u = -1;
    for (int i = (len - 1); i >= (0); i--) {
      if (str[i] == '\'') trig = i;
      if (str[i] == ' ') {
        if (u == -1)
          u = -2;
        else {
          u = i + 1;
          break;
        }
      }
    }
    for (int i = (u); i <= (trig - 1); i++) b += str[i];
    int id;
    if (b == myname) swap(a, b);
    if (a == myname) {
      if (!M.count(b)) {
        id = M[b] = ++p;
        s[p] = (ppl){0, b};
      } else
        id = M[b];
      s[id].point += pt;
    } else {
      if (!M.count(a)) {
        id = M[a] = ++p;
        s[p] = (ppl){0, a};
      }
      if (!M.count(b)) {
        id = M[b] = ++p;
        s[p] = (ppl){0, b};
      }
    }
  }
  sort(s + 1, s + p + 1);
  for (int i = (1); i <= (p); i++) cout << s[i].so << endl;
  return 0;
}
