#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y % 2 == 0) {
      x = (x * x);
      y /= 2;
    } else {
      res = (res * x);
      y--;
    }
  }
  return res;
}
void sieve() {
  vector<bool> prime(1e6 + 1, true);
  prime[0] = prime[1] = false;
  for (long long int i = 2; i * i <= 1e6; i++) {
    if (prime[i]) {
      for (long long int j = i * i; j <= 1e6; j += i) prime[j] = false;
    }
  }
}
bool is_Balanced_Parenthesis(string s) {
  stack<char> st;
  for (auto it : s) {
    if (it == '(' || it == '{' || it == '[') {
      st.push(it);
      continue;
    }
    if (st.empty()) return false;
    if (it == ')') {
      char ch = st.top();
      st.pop();
      if (ch != '(') return false;
    }
    if (it == ']') {
      char ch = st.top();
      st.pop();
      if (ch != '[') return false;
    }
    if (it == '}') {
      char ch = st.top();
      st.pop();
      if (ch != '{') return false;
    }
  }
  return st.empty();
}
bool comp(pair<long long int, string> &a, pair<long long int, string> &b) {
  if (b.first < a.first)
    return true;
  else if (b.first == a.first) {
    return (a.second < b.second);
  }
  return false;
}
void solve() {
  string s;
  cin >> s;
  long long int n;
  cin >> n;
  map<string, long long int> x;
  for (long long int i = 0; i < n; i++) {
    string name1, name2, temp, action, p;
    cin >> name1;
    cin >> action;
    if (action == "posted" || action == "commented") cin >> temp;
    cin >> name2 >> p;
    name2.pop_back();
    name2.pop_back();
    long long int points = 5;
    if (action == "posted") points = 15;
    if (action == "commented") points = 10;
    if (name1 == s) {
      x[name2] += points;
    } else if (name2 == s) {
      x[name1] += points;
    }
    x[name2] += 0;
    x[name1] += 0;
  }
  vector<pair<long long int, string>> ans;
  for (auto it : x) {
    if (it.first == s) continue;
    ans.push_back({it.second, it.first});
  }
  sort(ans.begin(), ans.end(), comp);
  for (auto it : ans) cout << it.second << "\n";
  return;
}
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  c_p_c();
  solve();
  return 0;
}
