#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  map<string, int> mp;
  string me;
  cin >> me;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b, c, no;
    cin >> a >> b;
    if (b != "likes") {
      cin >> no;
    }
    cin >> c;
    c = c.substr(0, c.length() - 2);
    cin >> no;
    if (a == me || c == me) {
      if (b == "posted") {
        mp[a] += 15;
        mp[c] += 15;
      } else if (b == "commented") {
        mp[a] += 10;
        mp[c] += 10;
      } else {
        mp[a] += 5;
        mp[c] += 5;
      }
    } else {
      mp[a] += 0;
      mp[c] += 0;
    }
  }
  vector<pair<int, string> > vec;
  for (map<string, int>::iterator t = mp.begin(); t != mp.end(); t++) {
    if (t->first == me) {
      continue;
    }
    vec.push_back(make_pair(-t->second, t->first));
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i].second << endl;
  }
  return 0;
}
