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