#include <bits/stdc++.h>
using namespace std;
const int N = 105;
set<string> name;
map<string, int> id;
string pos[N];
string s, st, o;
int n, a[N], cnt;
void add(string x) {
  if (name.find(x) != name.end()) return;
  name.insert(x);
  cnt++;
  id[x] = cnt;
  pos[cnt] = x;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> st;
  add(st);
  cin >> n;
  getline(cin, st);
  for (int i = 1; i <= n; ++i) {
    getline(cin, st);
    stringstream ss(st);
    string tmp;
    vector<string> v;
    while (ss >> tmp) {
      v.emplace_back(tmp);
    }
    add(v[0]);
    if (v[1] == "posted") {
      v[3].pop_back();
      v[3].pop_back();
      add(v[3]);
      int u = id[v[0]], vv = id[v[3]];
      if (u == 1 || vv == 1) {
        a[u] += 15, a[vv] += 15;
      }
    }
    if (v[1] == "commented") {
      v[3].pop_back();
      v[3].pop_back();
      add(v[3]);
      int u = id[v[0]], vv = id[v[3]];
      if (u == 1 || vv == 1) {
        a[u] += 10, a[vv] += 10;
      }
    }
    if (v[1] == "likes") {
      v[2].pop_back();
      v[2].pop_back();
      add(v[2]);
      int u = id[v[0]], vv = id[v[2]];
      if (u == 1 || vv == 1) {
        a[u] += 5, a[vv] += 5;
      }
    }
  }
  sort(pos + 2, pos + cnt + 1, [](string x, string y) {
    return a[id[x]] != a[id[y]] ? a[id[x]] > a[id[y]] : x < y;
  });
  for (int i = 2; i <= cnt; ++i) cout << pos[i] << '\n';
}
