#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<string> b;
int nom[10000];
string de(string s1) {
  string s = "";
  for (int i = 0; i < s1.size() - 2; i++) s += s1[i];
  return s;
}
bool f(int x, int y) { return (a[x] > a[y] || (a[x] == a[y] && b[x] < b[y])); }
int main() {
  string s;
  cin >> s;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    string s1, s3, s2;
    cin >> s3 >> s1;
    int kol = 0;
    if (s1 == "likes") {
      cin >> s2 >> s1;
      kol = 5;
    } else {
      if (s1 == "posted")
        kol = 15;
      else
        kol = 10;
      cin >> s1 >> s2 >> s1;
    }
    s2 = de(s2);
    string S = "";
    if (s2 == s)
      S = s3;
    else if (s3 == s)
      S = s2;
    else {
      kol = 0;
      int o = 0;
      S = s3;
      for (int j = 0; j < b.size(); j++) {
        if (b[j] == S) {
          a[j] += kol;
          o = 1;
          break;
        }
      }
      if (o == 0) {
        nom[b.size()] = b.size();
        a.push_back(kol);
        b.push_back(S);
      }
      o = 0;
      S = s2;
      for (int j = 0; j < b.size(); j++) {
        if (b[j] == S) {
          a[j] += kol;
          o = 1;
          break;
        }
      }
      if (o == 0) {
        nom[b.size()] = b.size();
        a.push_back(kol);
        b.push_back(S);
      }
    }
    int o = 0;
    for (int j = 0; j < b.size(); j++) {
      if (b[j] == S) {
        a[j] += kol;
        o = 1;
        break;
      }
    }
    if (o == 0) {
      nom[b.size()] = b.size();
      a.push_back(kol);
      b.push_back(S);
    }
  }
  sort(nom, nom + b.size(), f);
  for (int i = 0; i < b.size(); i++) cout << b[nom[i]] << endl;
  return 0;
}
