#include <bits/stdc++.h>
using namespace std;
string name;
int n;
map<string, int> m;
void D(string s, vector<string>& vs) {
  vs.clear();
  string f = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != ' ')
      f += s[i];
    else {
      vs.push_back(f);
      f.clear();
    }
  }
  vs.push_back(f);
  if (vs.size() == 5) {
    vs[3] = vs[3].substr(0, vs[3].size() - 2);
  } else {
    vs[2] = vs[2].substr(0, vs[2].size() - 2);
  }
}
bool cmp(const pair<string, int>& p1, const pair<string, int>& p2) {
  if (p1.second != p2.second) return p1.second > p2.second;
  return p1.first < p2.first;
}
int main() {
  cin >> name;
  cin >> n;
  string tmp;
  getline(cin, tmp);
  for (int i = 0; i < n; i++) {
    vector<string> vs;
    string s;
    getline(cin, s);
    D(s, vs);
    if (vs.size() == 4) {
      if (vs[0] == name) {
        m[vs[2]] += 5;
      } else if (vs[2] == name) {
        m[vs[0]] += 5;
      } else {
        m[vs[0]] += 0;
        m[vs[2]] += 0;
      }
    } else {
      if (vs[1] == "posted") {
        if (vs[0] == name) {
          m[vs[3]] += 15;
        } else if (vs[3] == name) {
          m[vs[0]] += 15;
        } else {
          m[vs[0]] += 0;
          m[vs[3]] += 0;
        }
      } else {
        if (vs[0] == name) {
          m[vs[3]] += 10;
        } else if (vs[3] == name) {
          m[vs[0]] += 10;
        } else {
          m[vs[0]] += 0;
          m[vs[3]] += 0;
        }
      }
    }
  }
  vector<pair<string, int> > v;
  v.clear();
  for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
    v.push_back(*it);
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << endl;
  }
  return 0;
}
