#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
const long long INF = 1e9 + 7;
map<string, long long> out;
string name;
void solve(string sentence) {
  string name1, name2;
  name1 = "";
  long long spacecount = 0;
  for (long long i = 0; i < sentence.size(); i++)
    if (sentence[i] == ' ') spacecount++;
  bool hasT = false;
  long long j = 0;
  while (sentence[j] != ' ') name1 += sentence[j], j++;
  if (sentence[sentence.size() - 1] == 't') hasT = true;
  long long spaces = 0;
  for (long long i = 0; i < sentence.size(); i++) {
    if (sentence[i] != ' ' && !(sentence[i] >= 'a' && sentence[i] <= 'z'))
      break;
    if (sentence[i] == ' ')
      spaces++;
    else {
      if (spacecount == 4) {
        if (spaces == 3) name2.push_back(sentence[i]);
      } else {
        if (spaces == 2) name2.push_back(sentence[i]);
      }
    }
  }
  for (long long i = 0; i < 2; i++) {
    if (name1 == name) {
      if (spacecount == 4) {
        if (hasT)
          out[name2] += 10;
        else
          out[name2] += 15;
      } else {
        out[name2] += 5;
      }
    } else {
      out[name1] += 0;
    }
    swap(name1, name2);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> name;
  long long n;
  cin >> n;
  string inn;
  getline(cin, inn);
  for (long long i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    solve(s);
  }
  vector<pair<long long, string> > res;
  for (auto i : out) {
    res.push_back(make_pair(-i.second, i.first));
  }
  sort(res.begin(), res.end());
  for (long long i = 0; i < res.size(); i++) cout << res[i].second << "\n";
}
