#include <bits/stdc++.h>
using namespace std;
set<string> p;
map<string, int> m;
vector<string> g;
vector<pair<int, string> > gs;
bool sortbysec(const pair<int, string> &a, const pair<int, string> &b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
void call(string str, string s) {
  istringstream ss(str);
  vector<string> g;
  do {
    string word;
    ss >> word;
    g.push_back(word);
  } while (ss);
  int siz = g.size();
  string s1 = g[0];
  string s2 = g[1];
  string s3 = g[siz - 3];
  int len = s3.length();
  s3.pop_back();
  s3.pop_back();
  if (s1 == s) {
    p.insert(s3);
    if (s2 == "posted") {
      m[s3] += 15;
    } else if (s2 == "commented") {
      m[s3] += 10;
    } else {
      m[s3] += 5;
    }
  } else if (s3 == s) {
    p.insert(s1);
    if (s2 == "posted") {
      m[s1] += 15;
    } else if (s2 == "commented") {
      m[s1] += 10;
    } else {
      m[s1] += 5;
    }
  } else {
    p.insert(s1);
    p.insert(s3);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, s1;
  pair<int, string> xp;
  cin >> s;
  int t;
  cin >> t;
  cin.ignore();
  while (t--) {
    getline(cin, s1);
    call(s1, s);
  }
  int siz = p.size();
  for (auto it : p) {
    gs.push_back(make_pair(m[it], it));
  }
  sort(gs.begin(), gs.end(), sortbysec);
  for (auto xp : gs) {
    cout << xp.second << endl;
  }
  return 0;
}
