#include <bits/stdc++.h>
using namespace std;
struct node {
  string s;
  int k;
};
node a[103];
map<string, int> m;
char s[1000], s1[100], s2[100], s3[100], s4[100];
string name;
int n, nn, p1, p2, k;
bool cmp(node a, node b) { return (a.k > b.k || (a.k == b.k && a.s < b.s)); }
int main() {
  m.clear();
  cin >> name;
  m[name] = nn = 1;
  scanf("%d", &n);
  gets(s);
  while (n--) {
    gets(s);
    sscanf(s, "%s %s %s %s", s1, s2, s3, s4);
    if (s2[0] == 'l') {
      k = 5;
      strcpy(s4, s3);
    }
    if (s2[0] == 'c') k = 10;
    if (s2[0] == 'p') k = 15;
    name = s1;
    if (m.find(name) == m.end()) {
      m[name] = ++nn;
      a[nn].s = name;
      a[nn].k = 0;
      p1 = nn;
    } else
      p1 = m[name];
    s4[strlen(s4) - 2] = '\0';
    name = s4;
    if (m.find(name) == m.end()) {
      m[name] = ++nn;
      a[nn].s = name;
      p2 = nn;
    } else
      p2 = m[name];
    if (p1 != 1 && p2 != 1) continue;
    if (p1 == 1) p1 = p2;
    a[p1].k += k;
  }
  sort(a + 2, a + nn + 1, cmp);
  for (int i = 2; i <= nn; ++i) cout << a[i].s << endl;
  return 0;
}
