#include <bits/stdc++.h>
using namespace std;
string s, temp;
map<string, int> mym;
vector<string> myv;
bool cmp(string s, string ss) {
  if (mym[s] == mym[ss]) return s < ss;
  return mym[s] > mym[ss];
}
int n, i, len;
int main() {
  cin >> s >> n;
  for (i = 0; i < n; i++) {
    string x, y, z, dd, e;
    cin >> x >> y >> z >> dd;
    if (y != "likes") {
      cin >> e;
      temp = dd.substr(0, dd.size() - 2);
      if (temp == s) {
        len = mym[x];
        if (y == "posted")
          len += 15;
        else
          len += 10;
        mym[x] = len;
      } else if (x == s) {
        len = mym[temp];
        if (y == "posted")
          len += 15;
        else
          len += 10;
        mym[temp] = len;
      } else {
        mym[temp] = mym[temp];
        mym[x] = mym[x];
      }
    } else {
      temp = z.substr(0, z.size() - 2);
      if (temp == s) {
        len = mym[x];
        len += 5;
        mym[x] = len;
      } else if (x == s) {
        len = mym[temp];
        len += 5;
        mym[temp] = len;
      } else {
        mym[temp] = mym[temp];
        mym[x] = mym[x];
      }
    }
  }
  map<string, int>::iterator rit;
  for (rit = mym.begin(); rit != mym.end(); ++rit) {
    myv.push_back(rit->first);
  }
  sort(myv.begin(), myv.end(), cmp);
  for (i = 0; i < myv.size(); ++i) cout << myv[i] << endl;
  return 0;
}
