#include <bits/stdc++.h>
using namespace std;
bool Sort(const pair<string, int>& x, const pair<string, int>& y) {
  return x.second == y.second ? x.first < y.first : x.second > y.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string name, action[5], temp;
  map<string, int> names, points;
  points["posted"] = 15;
  points["commented"] = 10;
  points["likes"] = 5;
  int n;
  cin >> name >> n;
  cin.ignore();
  while (n--) {
    for (int i = 0; i < 5; ++i) {
      cin >> action[i];
      if (i == 1 && action[i] == "likes") i++;
    }
    string name1 = action[0],
           name2 = action[3].substr(0, action[3].length() - 2);
    if (name1 == name || name2 == name) {
      names[(name1 == name ? name2 : name1)] += points[action[1]];
    } else {
      names[name1] += 0;
      names[name2] += 0;
    }
  }
  vector<pair<string, int>> ans(((names).begin()), ((names).end()));
  sort(((ans).begin()), ((ans).end()), Sort);
  for (const auto& k : ans) cout << k.first << "\n";
  return 0;
}
