#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string name, com("commented"), post("posted"), like("likes"), fir("A");
  cin >> name;
  long long n, mx = 0, k = 1;
  cin >> n;
  vector<pair<long long, string> > s;
  s.push_back(make_pair(0, fir));
  map<string, long long> m;
  for (long long i = 0; i < n; i++) {
    string t1, t2, t3, t4, t5;
    cin >> t1 >> t2;
    if (t2 == like) {
      cin >> t3 >> t4;
      long long size = t3.size();
      t3.erase(size - 2);
      if (t1 == name) {
        if (m[t3] == 0) {
          m[t3] = k;
          s.push_back(make_pair(5, t3));
          ++k;
        } else {
          s[m[t3]].first += 5;
        }
      } else if (t3 == name) {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(5, t1));
          ++k;
        } else {
          s[m[t1]].first += 5;
        }
      } else {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(0, t1));
          ++k;
        }
        if (m[t3] == 0) {
          m[t3] = k;
          s.push_back(make_pair(0, t3));
          ++k;
        }
      }
    } else if (t2 == com) {
      cin >> t3 >> t4 >> t5;
      long long size = t4.size();
      t4.erase(size - 2);
      if (t1 == name) {
        if (m[t4] == 0) {
          m[t4] = k;
          s.push_back(make_pair(10, t4));
          ++k;
        } else {
          s[m[t4]].first += 10;
        }
      } else if (t4 == name) {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(10, t1));
          ++k;
        } else {
          s[m[t1]].first += 10;
        }
      } else {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(0, t1));
          ++k;
        }
        if (m[t4] == 0) {
          m[t4] = k;
          s.push_back(make_pair(0, t4));
          ++k;
        }
      }
    } else if (t2 == post) {
      cin >> t3 >> t4 >> t5;
      long long size = t4.size();
      t4.erase(size - 2);
      if (t1 == name) {
        if (m[t4] == 0) {
          m[t4] = k;
          s.push_back(make_pair(15, t4));
          ++k;
        } else {
          s[m[t4]].first += 15;
        }
      } else if (t4 == name) {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(15, t1));
          ++k;
        } else {
          s[m[t1]].first += 15;
        }
      } else {
        if (m[t1] == 0) {
          m[t1] = k;
          s.push_back(make_pair(0, t1));
          ++k;
        }
        if (m[t4] == 0) {
          m[t4] = k;
          s.push_back(make_pair(0, t4));
          ++k;
        }
      }
    }
  }
  sort(s.begin(), s.end());
  long long sz = s.size(), chk = s[sz - 1].first, l = 0;
  vector<string> sf[sz];
  for (long long i = sz - 1; i > 0; i--) {
    if (s[i].first == chk) {
      sf[l].push_back(s[i].second);
    } else {
      ++l;
      chk = s[i].first;
      sf[l].push_back(s[i].second);
    }
  }
  for (long long i = 0; i <= l; i++) {
    sort(sf[i].begin(), sf[i].end());
  }
  for (long long i = 0; i <= l; i++) {
    long long siz = sf[i].size();
    for (long long j = 0; j < siz; j++) {
      string op = sf[i][j];
      cout << op << '\n';
    }
  }
}
