#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  run();
  int n;
  string name;
  map<string, int> mp;
  cin >> name >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    stringstream ss(s);
    vector<string> v;
    while (ss >> s) v.push_back(s);
    int score = 0;
    if (v[1] == "posted")
      score = 15;
    else if (v[1] == "commented")
      score = 10;
    else if (v[1] == "likes")
      score = 5;
    int x = 3;
    if (v.size() == 5)
      x = 3;
    else
      x = 2;
    v[x].pop_back();
    v[x].pop_back();
    if (v[0] != name && v[x] != name) {
      mp[v[0]];
      mp[v[x]];
    } else if (v[0] == name)
      mp[v[x]] += score;
    else
      mp[v[0]] += score;
  }
  vector<pair<int, string>> v;
  for (auto it : mp) v.push_back({-it.second, it.first});
  sort(v.begin(), v.end());
  for (auto it : v) cout << it.second << "\n";
}
