#include <bits/stdc++.h>
using namespace std;
map<string, int> mop;
bool cmp(string x, string y) {
  if (mop[x] == mop[y]) return x < y;
  return mop[x] > mop[y];
}
int main() {
  string name;
  cin >> name;
  int n;
  cin >> n;
  vector<string> vec;
  while (n--) {
    string a, b, c, d, e;
    cin >> a >> b >> c >> d;
    string x, y;
    if (d != "post") cin >> e;
    if (d == "post") {
      x = c.substr(0, c.size() - 2);
      y = a;
      if (x == name)
        mop[y] += 5;
      else if (y == name)
        mop[x] += 5;
      else {
        mop[x] = mop[x], mop[y] = mop[y];
      }
    } else {
      x = d.substr(0, d.size() - 2);
      y = a;
      if (x == name) {
        if (b == "posted")
          mop[y] += 15;
        else
          mop[y] += 10;
      } else if (y == name) {
        if (b == "posted")
          mop[x] += 15;
        else
          mop[x] += 10;
      } else {
        mop[x] = mop[x], mop[y] = mop[y];
      }
    }
  }
  for (map<string, int>::iterator it = mop.begin(); it != mop.end(); it++) {
    vec.push_back((*it).first);
  }
  sort(vec.begin(), vec.end(), cmp);
  for (int i = 0; i < vec.size(); i++) cout << vec[i] << endl;
  return 0;
}
