#include <bits/stdc++.h>
using namespace std;
string you;
char buf[100];
map<string, int> mp;
vector<pair<int, string> > people;
void func(vector<string> &vs) {
  int p = 0;
  string X, Y;
  if (vs[1][0] == 'p') {
    p = 15;
    X = vs[0];
    Y = vs[3].substr(0, vs[3].length() - 2);
  } else if (vs[1][0] == 'c') {
    p = 10;
    X = vs[0];
    Y = vs[3].substr(0, vs[3].length() - 2);
  } else {
    p = 5;
    X = vs[0];
    Y = vs[2].substr(0, vs[2].length() - 2);
  }
  if (mp.find(X) == mp.end()) mp[X] = 0;
  if (mp.find(Y) == mp.end()) mp[Y] = 0;
  if (X == you) mp[Y] += p;
  if (Y == you) mp[X] += p;
}
int main(void) {
  int N, i;
  scanf("%s", buf);
  you = buf;
  scanf("%d", &N);
  gets(buf);
  for ((i) = 0; (i) < (int)(N); (i)++) {
    gets(buf);
    string s = buf;
    istringstream ss(s);
    vector<string> vs;
    string t;
    while (ss >> t) vs.push_back(t);
    func(vs);
  }
  for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++)
    if ((itr->first) != you)
      people.push_back(make_pair(-(itr->second), (itr->first)));
  sort(people.begin(), people.end());
  for ((i) = 0; (i) < (int)(people.size()); (i)++)
    cout << people[i].second << endl;
  return 0;
}
