#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int N = 100 + 5;
int n;
struct node {
  int s;
  string nam;
} stu[N];
map<string, int> mp;
bool cmp(node &a, node &b) { return a.s == b.s ? a.nam < b.nam : a.s > b.s; }
string chair;
string in;
int main() {
  cin >> chair;
  cin >> n;
  getchar();
  for (int i = 0; i < (n); i++) {
    getline(cin, in);
    stringstream ss(in);
    string s1, s2, ac, t;
    char tmp[N];
    int score = 0;
    ss >> s1;
    ss >> ac;
    if (ac[0] == 'p') {
      ss >> t;
      score = 15;
    } else if (ac[0] == 'c') {
      ss >> t;
      score = 10;
    } else if (ac[0] == 'l')
      score = 5;
    ss >> tmp;
    tmp[strlen(tmp) - 2] = '\0';
    s2 = tmp;
    if (s1 != chair && s2 != chair) {
      if (mp.find(s1) == mp.end()) mp[s1] = 0;
      if (mp.find(s2) == mp.end()) mp[s2] = 0;
    } else {
      if (s1 == chair) mp[s2] += score;
      if (s2 == chair) mp[s1] += score;
    }
  }
  int num = 0;
  map<string, int>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    stu[num].nam = it->first;
    stu[num++].s = it->second;
  }
  sort(stu, stu + num, cmp);
  for (int i = 0; i < (num); i++) cout << stu[i].nam << endl;
  return 0;
}
