#include <bits/stdc++.h>
using namespace std;
void solve() {
  string name;
  cin >> name;
  long long int n, i, j, c = 0;
  cin >> n;
  map<string, long long int> m;
  string x, y, Y, todo, on, wall;
  while (n--) {
    cin >> x;
    cin >> todo;
    if (todo == "posted" || todo == "commented") cin >> on;
    cin >> Y;
    y = Y.substr(0, Y.size() - 2);
    cin >> wall;
    long long int points;
    if (todo == "posted")
      points = 15;
    else if (todo == "commented")
      points = 10;
    else
      points = 5;
    if (x == name)
      m[y] += points;
    else
      m[x];
    if (y == name)
      m[x] += points;
    else
      m[y];
    cout << endl;
  }
  vector<pair<long long int, string>> ans;
  for (auto it = m.begin(); it != m.end(); it++) {
    ans.push_back({-it->second, it->first});
  }
  sort(ans.begin(), ans.end());
  for (i = 0; i < ans.size(); i++) cout << ans[i].second << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  while (t--) solve();
  cerr << "\nTime elapsed: " << setprecision(5)
       << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
