#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  string name;
  cin >> name;
  deque<pair<int, string> > answer;
  map<string, int> relative_map;
  int num;
  cin >> num;
  string input;
  for (int i = 0; i < (int)(num); i++) {
    if (!i) cin.ignore();
    getline(cin, input);
    int x = input.find(" ");
    string choice = "";
    for (int j = x + 1; j < (int)(input.size()); j++) {
      if (input[j] != ' ')
        choice += input[j];
      else
        break;
    }
    string first = "", second = "";
    for (int j = 0; j < (int)(input.length()); j++) {
      if (input[j] != ' ')
        first += input[j];
      else
        break;
    }
    if (choice == "posted") {
      for (int j = x + 11; j < (int)(input.length()); j++) {
        if (input[j] != '\'')
          second += input[j];
        else
          break;
      }
      if (first != name && second != name) {
        relative_map[first];
        relative_map[second];
      } else {
        if (first == name) {
          relative_map[second] += 15;
        }
        if (second == name) {
          relative_map[first] += 15;
        }
      }
    } else if (choice == "commented") {
      for (int j = x + 14; j < (int)(input.length()); j++) {
        if (input[j] != '\'')
          second += input[j];
        else
          break;
      }
      if (first != name && second != name) {
        relative_map[first];
        relative_map[second];
      } else {
        if (first == name) {
          relative_map[second] += 10;
        }
        if (second == name) {
          relative_map[first] += 10;
        }
      }
    } else if (choice == "likes") {
      for (int j = x + 7; j < (int)(input.length()); j++) {
        if (input[j] != '\'')
          second += input[j];
        else
          break;
      }
      if (first != name && second != name) {
        relative_map[first];
        relative_map[second];
      } else {
        if (first == name) {
          relative_map[second] += 5;
        }
        if (second == name) {
          relative_map[first] += 5;
        }
      }
    }
  }
  for (map<string, int>::iterator it = relative_map.begin();
       it != relative_map.end(); it++)
    answer.push_back(make_pair(-it->second, it->first));
  sort(((answer).begin()), ((answer).end()));
  for (int i = 0; i < (int)(((int)((answer).size()))); i++)
    cout << answer[i].second << endl;
}
