#include <bits/stdc++.h>
using namespace std;
class Point {
  int x;
  string y;

 public:
  Point(int _x, string _y) {
    x = _x;
    y = _y;
  }
  int getX() const { return x; }
  string getY() const { return y; }
};
class myComparator {
 public:
  int operator()(const Point& p1, const Point& p2) {
    if (p1.getX() == p2.getX()) return (p1.getY() > p2.getY());
    return p1.getX() < p2.getX();
  }
};
int main() {
  string name;
  cin >> name;
  int n;
  cin >> n;
  std::vector<vector<string>> a(n);
  for (int i = 0; i < n; i++) {
    string t;
    for (int j = 0; j < 5; j++) {
      cin >> t;
      a[i].push_back(t);
      if (j > 1) {
        if (a[i][1] == "likes" && j == 3) break;
      }
    }
  }
  unordered_map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string name1, name2;
    int val;
    if (a[i][1] == "posted") {
      name1 = a[i][0];
      name2 = a[i][3].substr(0, a[i][3].length() - 2);
      val = 15;
    } else if (a[i][1] == "commented") {
      name1 = a[i][0];
      name2 = a[i][3].substr(0, a[i][3].length() - 2);
      val = 10;
    } else {
      name1 = a[i][0];
      name2 = a[i][2].substr(0, a[i][2].length() - 2);
      val = 5;
    }
    if (name1 == name)
      mp[name2] += val;
    else
      mp[name1] += 0;
    if (name2 == name)
      mp[name1] += val;
    else
      mp[name2] += 0;
  }
  priority_queue<Point, vector<Point>, myComparator> pq;
  for (auto it : mp) {
    pq.push(Point(it.second, it.first));
  }
  while (!pq.empty()) {
    Point t = pq.top();
    pq.pop();
    if (t.getY() != name) cout << t.getY() << endl;
  }
}
