#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
map<string, long long> mp;
map<string, long long> mp1;
class cmp {
 public:
  bool operator()(const pair<long long, string> &a,
                  const pair<long long, string> &b) {
    if (a.first != b.first) {
      return a.first < b.first;
    } else {
      return a.second > b.second;
    }
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string me, ss;
  mp["commented"] = 10, mp["posted"] = 15, mp["likes"] = 5;
  cin >> me;
  long long n;
  cin >> n;
  cin.ignore();
  priority_queue<pair<long long, string>, vector<pair<long long, string> >, cmp>
      qq;
  for (long long i = 0; i < n; i++) {
    getline(cin, ss);
    vector<string> temp;
    string res;
    for (long long j = 0; j < (long long)ss.length(); j++) {
      if (temp.size() == 3) break;
      if (ss[j] == ' ') {
        if (res == "on" && temp.size() == 2) {
          res = "";
          continue;
        }
        if (temp.size() == 2) {
          res.pop_back();
          res.pop_back();
        }
        temp.push_back(res);
        res = "";
      } else {
        res += ss[j];
      }
    }
    if (temp.size() == 3) {
      if (temp.back() == me) {
        mp1[temp[0]] += mp[temp[1]];
      } else if (temp[0] == me) {
        mp1[temp.back()] += mp[temp[1]];
      } else {
        mp1[temp.back()] += 0;
        mp1[temp[0]] += 0;
      }
    }
  }
  for (auto ff : mp1) {
    qq.push({ff.second, ff.first});
  }
  while (!qq.empty()) {
    cout << qq.top().second << "\n";
    qq.pop();
  }
  return 0;
}
