#include <bits/stdc++.h>
using namespace std;
const int xx[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int yy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int kx[] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int ky[] = {1, 2, 2, 1, -1, -2, -2, -1};
class data {
 public:
  char st[15];
  int point;
  data() { point = 0; }
};
char myname[15];
char str[70];
char fnam[15];
char snam[15];
vector<int> v;
map<string, int> mp;
map<int, string> mpi;
vector<data> vd;
void first_name(int x) {
  int i;
  for (i = 0; i < x; i++) fnam[i] = str[i];
  fnam[i] = '\0';
}
void sceond_name(int x, int coma) {
  int i, j;
  for (i = x + 1, j = 0; i < coma; i++, j++) snam[j] = str[i];
  snam[j] = '\0';
}
bool compare(data a, data b) {
  if (a.point == b.point) {
    return strcmp(a.st, b.st) < strcmp(b.st, a.st);
  } else
    return a.point > b.point;
}
int main() {
  int n, i, j, k, hicoma, score, idx, z;
  data d;
  scanf("%s", myname);
  getchar();
  scanf("%d", &n);
  getchar();
  idx = 1;
  for (i = 0; i < n; i++) {
    gets(str);
    for (j = 0; str[j]; j++)
      if (str[j] == ' ') {
        v.push_back(j);
      } else if (str[j] == 39)
        hicoma = j;
    first_name(v[0]);
    if (str[v[0] + 1] == 'p')
      score = 15;
    else if (str[v[0] + 1] == 'c')
      score = 10;
    else
      score = 5;
    if (score == 5)
      sceond_name(v[1], hicoma);
    else
      sceond_name(v[2], hicoma);
    if (strcmp(myname, fnam) != 0 && !mp[fnam]) {
      mp[fnam] = idx;
      mpi[idx++] = fnam;
      strcpy(d.st, fnam);
      d.point = 0;
      vd.push_back(d);
    }
    if (strcmp(myname, snam) != 0 && !mp[snam]) {
      mp[snam] = idx;
      mpi[idx++] = snam;
      strcpy(d.st, snam);
      d.point = 0;
      vd.push_back(d);
    }
    if (strcmp(myname, fnam) == 0) {
      z = mp[snam] - 1;
      vd[z].point += score;
    }
    if (strcmp(myname, snam) == 0) {
      z = mp[fnam] - 1;
      vd[z].point += score;
    }
    v.clear();
  }
  sort(vd.begin(), vd.end(), compare);
  z = vd.size();
  for (i = 0; i < z; i++) printf("%s\n", vd[i].st);
  return 0;
}
