#include <bits/stdc++.h>
using namespace std;
int n;
string you;
char buf[100];
map<string, int> mp;
vector<pair<int, string> > v;
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() {
  cin >> buf;
  you = buf;
  cin >> n;
  gets(buf);
  for (int i = 0; i < 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()) i = mp.begin(); i != mp.end(); i++) {
    if (i->first != you) v.push_back(make_pair(-(i->second), (i->first)));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) cout << v[i].second << endl;
  return 0;
}
