#include <bits/stdc++.h>
using namespace std;
class PERSON {
 public:
  int val, id;
} arr[205];
int m, n;
string name[205];
bool cmp(const PERSON &a, const PERSON &b) {
  if (a.val != b.val) return a.val > b.val;
  return name[a.id] < name[b.id];
}
map<string, int> mp;
map<string, int>::iterator it;
char str[15];
string st;
int main() {
  FILE *in = stdin;
  int c, c2;
  mp.clear();
  memset(arr, 0, sizeof(arr));
  fscanf(in, "%s", str);
  st = str;
  mp[st] = 0;
  name[0] = st;
  arr[0].id = 0;
  arr[0].val = 0;
  n = 0;
  n++;
  fscanf(in, "%d", &m);
  for (c = 0; c < m; c++) {
    fscanf(in, "%s", str);
    st = str;
    int fact;
    int i;
    if (mp.find(st) == mp.end()) {
      mp[st] = n;
      name[n] = st;
      arr[n].id = n;
      i = n;
      n++;
    } else
      i = mp[st];
    fscanf(in, "%s", str);
    st = str;
    if (st == "posted")
      fact = 15;
    else if (st == "commented")
      fact = 10;
    else
      fact = 5;
    if (fact > 5) fscanf(in, "%*s");
    fscanf(in, "%s", str);
    st = str;
    st.erase(((int)(st.size())) - 2, 2);
    int i2;
    if (mp.find(st) == mp.end()) {
      mp[st] = n;
      name[n] = st;
      arr[n].id = n;
      i2 = n;
      n++;
    } else
      i2 = mp[st];
    if (i == 0 || i2 == 0) {
      arr[i].val += fact;
      arr[i2].val += fact;
    }
    fscanf(in, "%*s");
  }
  sort(arr, arr + n, cmp);
  for (c = 0; c < n; c++) {
    if (arr[c].id == 0) continue;
    printf("%s\n", name[arr[c].id].c_str());
  }
  return 0;
}
