#include <bits/stdc++.h>
using namespace std;
map<string, int> m, mp;
set<pair<int, string>> pq;
string me, nam1, nam2, p, on, f;
int n, x, v, y;
int main() {
  mp["posted"] = 15;
  mp["commented"] = 10;
  mp["likes"] = 5;
  cin >> me >> n;
  while (n) {
    cin >> nam1 >> p;
    if (p[0] == 'p' || p[0] == 'c') cin >> on;
    cin >> nam2 >> f;
    nam2.pop_back();
    nam2.pop_back();
    if (me == nam1)
      m[nam2] += mp[p];
    else if (me == nam2)
      m[nam1] += mp[p];
    else {
      m[nam1] += 0;
      m[nam2] += 0;
    }
    n--;
  }
  auto it = m.begin();
  for (; it != m.end(); it++) pq.insert(make_pair(-(*it).second, (*it).first));
  auto t = pq.begin();
  for (; t != pq.end(); t++) cout << (*t).second << "\n";
  return 0;
}
