#include <bits/stdc++.h>
const int N = 100010;
const int inf = 0x3f3f3f3f;
using namespace std;
struct data {
  int p;
  string str;
  bool operator<(const data &r) const {
    if (p != r.p) return p > r.p;
    return str < r.str;
  }
} da[N];
string work(string str) {
  string s = "";
  int k = 0;
  while (str[k] != '\'') s += str[k], k++;
  return s;
}
int main() {
  int n;
  string na;
  map<string, int> mp;
  cin >> na >> n;
  mp[na] = 2 * n + 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if (!mp[str]) mp[str] = ++cnt;
    int x = mp[str], y = -1;
    da[x].str = str;
    cin >> str;
    if (str[0] == 'p') {
      cin >> str >> str;
      str = work(str);
      if (!mp[str]) mp[str] = ++cnt;
      y = mp[str];
      da[y].str = str;
      string s;
      cin >> s;
      if (x != 2 * n + 1 && y != 2 * n + 1) continue;
      da[y].p += 15;
      da[x].p += 15;
    } else if (str[0] == 'c') {
      cin >> str >> str;
      str = work(str);
      if (!mp[str]) mp[str] = ++cnt;
      y = mp[str];
      da[y].str = str;
      string s;
      cin >> s;
      if (x != 2 * n + 1 && y != 2 * n + 1) continue;
      da[y].p += 10;
      da[x].p += 10;
    } else {
      cin >> str;
      str = work(str);
      if (!mp[str]) mp[str] = ++cnt;
      y = mp[str];
      da[y].str = str;
      string s;
      cin >> s;
      if (x != 2 * n + 1 && y != 2 * n + 1) continue;
      da[y].p += 5;
      da[x].p += 5;
    }
  }
  sort(da + 1, da + 1 + cnt);
  for (int i = 1; i <= cnt; i++) {
    cout << da[i].str << endl;
  }
  return 0;
}
