#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long n;
  cin >> n;
  vector<pair<long long, string>> v;
  while (n--) {
    string name1, decider, name2;
    cin >> name1 >> decider;
    if (decider == "posted" or decider == "commented") {
      string a, b;
      cin >> a >> name2 >> b;
    } else {
      string a;
      cin >> name2 >> a;
    }
    name2 = name2.substr(0, name2.length() - 2);
    if (s == name1) {
      int flag = 0;
      for (long long i = 0; i < v.size(); i++) {
        if (v[i].second == name2) {
          flag = 1;
          if (decider == "posted")
            v[i].first = v[i].first + 15;
          else if (decider == "commented")
            v[i].first = v[i].first + 10;
          else
            v[i].first = v[i].first + 5;
          break;
        }
      }
      if (flag == 0) {
        if (decider == "posted")
          v.push_back(make_pair(15, name2));
        else if (decider == "commented")
          v.push_back(make_pair(10, name2));
        else
          v.push_back(make_pair(5, name2));
      }
    } else if (s == name2) {
      int flag = 0;
      for (long long i = 0; i < v.size(); i++) {
        if (v[i].second == name1) {
          flag = 1;
          if (decider == "posted")
            v[i].first = v[i].first + 15;
          else if (decider == "commented")
            v[i].first = v[i].first + 10;
          else
            v[i].first = v[i].first + 5;
          break;
        }
      }
      if (flag == 0) {
        if (decider == "posted")
          v.push_back(make_pair(15, name1));
        else if (decider == "commented")
          v.push_back(make_pair(10, name1));
        else
          v.push_back(make_pair(5, name1));
      }
    } else {
      int flag1 = 0, flag2 = 0;
      for (long long i = 0; i < v.size(); i++) {
        if (v[i].second == name1) {
          flag1 = 1;
          break;
        }
      }
      for (long long i = 0; i < v.size(); i++) {
        if (v[i].second == name2) {
          flag2 = 1;
          break;
        }
      }
      if (flag1 == 0) {
        v.push_back(make_pair(0, name1));
      }
      if (flag2 == 0) {
        v.push_back(make_pair(0, name2));
      }
    }
  }
  sort(v.begin(), v.end());
  vector<long long> v1;
  v1.push_back(v[0].first);
  for (long long i = 1; i < v.size(); i++) {
    if (v[i].first != v1[v1.size() - 1]) v1.push_back(v[i].first);
  }
  long long ar[v.size()];
  memset(ar, 0, sizeof(ar));
  for (long long i = v1.size() - 1; i >= 0; i--) {
    for (long long j = 0; j < v.size(); j++) {
      if (v1[i] == v[j].first and ar[j] == 0) {
        cout << v[j].second << endl;
        ar[j] = 1;
      }
    }
  }
  return 0;
}
