#include <bits/stdc++.h>
using namespace std;
int main() {
  string me;
  cin >> me;
  int n;
  cin >> n;
  map<string, int> mp, S{{"posted", 15}, {"commented", 10}, {"likes", 5}};
  for (int i = 0; i < n; i++) {
    string a, b, c, x;
    cin >> a >> b >> c >> x;
    if (c == "on") {
      c = x;
      cin >> x;
    }
    c.pop_back();
    c.pop_back();
    if (a == me) {
      mp[c] += S[b];
    }
    if (c == me) {
      mp[a] += S[b];
    }
    mp.insert(pair<string, int>(a, 0));
    mp.insert(pair<string, int>(c, 0));
  }
  vector<pair<int, string>> v;
  for (auto i : mp) {
    v.emplace_back(-i.second, i.first);
  }
  sort(v.begin(), v.end());
  for (auto i : v) {
    if (i.second != me) cout << i.second << '\n';
  }
  return 0;
}
