#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
template <class T>
bool inside(T a, T b, T c) {
  return (b >= a && b <= c);
}
double dist(double x1, double y1, double x2, double y2) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
double dist(int x1, int y1, int x2, int y2) {
  return sqr(x1 - x2) + sqr(y1 - y2);
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
long long toInt64(string s) {
  long long r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
double toDouble(string s) {
  double r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
struct node {
  string S;
  int p;
};
int compare(node a, node b) {
  if (a.p == b.p) {
    return b.S > a.S;
  }
  return b.p < a.p;
}
int main() {
  string ME;
  cin >> ME;
  int T;
  cin >> T;
  getchar();
  map<string, int> MP;
  map<string, int>::iterator it;
  while (T--) {
    string S, W;
    getline(cin, S);
    istringstream sin(S);
    int cnt = 0;
    string name = "", act = "", tmp = "", name2 = "", place = "";
    while (sin >> W) {
      if (cnt == 0) name = W;
      if (cnt == 1) act = W;
      if (cnt == 2) tmp = W;
      if (cnt == 3) name2 = W;
      if (cnt == 4) place == W;
      cnt++;
    }
    if (tmp != "on") {
      place = name2;
      name2 = tmp;
    }
    name2.erase(name2.end() - 1);
    name2.erase(name2.end() - 1);
    if (name != ME && name2 != ME) {
      MP[name] += 0;
      MP[name2] += 0;
      continue;
    }
    if (act == "posted") {
      MP[name] += 15;
      MP[name2] += 15;
    }
    if (act == "commented") {
      MP[name] += 10;
      MP[name2] += 10;
    }
    if (act == "likes") {
      MP[name] += 5;
      MP[name2] += 5;
    }
  }
  vector<node> V;
  for (it = MP.begin(); it != MP.end(); it++) {
    node temp;
    temp.S = (*it).first;
    temp.p = (*it).second;
    if (temp.S != ME) V.push_back(temp);
  }
  sort(V.begin(), V.end(), compare);
  for (int i = 0; i < (int)V.size(); i++) {
    cout << V[i].S << endl;
  }
  return 0;
}
