Problem: Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).

This priority factor will be affected by three types of actions: 

  * 1. "X posted on Y's wall" (15 points), 
  * 2. "X commented on Y's post" (10 points), 
  * 3. "X likes Y's post" (5 points). 



X and Y will be two distinct names. And each action will increase the priority factor between X and Y (and vice versa) by the above value of points (the priority factor between X and Y is the same as the priority factor between Y and X).

You will be given n actions with the above format (without the action number and the number of points), and you have to print all the distinct names in these actions sorted according to the priority factor with you.

Input

The first line contains your name. The second line contains an integer n, which is the number of actions (1 ≤ n ≤ 100). Then n lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra spaces. All the letters are lowercase. All names in the input will consist of at least 1 letter and at most 10 small Latin letters.

Output

Print m lines, where m is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority factor, print them in the alphabetical (lexicographical) order.

Note, that you should output all the names that are present in the input data (excluding yourself), even if that person has a zero priority factor.

The lexicographical comparison is performed by the standard "<" operator in modern programming languages. The line a is lexicographically smaller than the line b, if either a is the prefix of b, or if exists such an i (1 ≤ i ≤ min(|a|, |b|)), that ai < bi, and for any j (1 ≤ j < i) aj = bj, where |a| and |b| stand for the lengths of strings a and b correspondently.

Examples

Input

ahmed
3
ahmed posted on fatma's wall
fatma commented on ahmed's post
mona likes ahmed's post


Output

fatma
mona


Input

aba
1
likes likes posted's post


Output

likes
posted

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y % 2 == 0) {
      x = (x * x);
      y /= 2;
    } else {
      res = (res * x);
      y--;
    }
  }
  return res;
}
void sieve() {
  vector<bool> prime(1e6 + 1, true);
  prime[0] = prime[1] = false;
  for (long long int i = 2; i * i <= 1e6; i++) {
    if (prime[i]) {
      for (long long int j = i * i; j <= 1e6; j += i) prime[j] = false;
    }
  }
}
bool is_Balanced_Parenthesis(string s) {
  stack<char> st;
  for (auto it : s) {
    if (it == '(' || it == '{' || it == '[') {
      st.push(it);
      continue;
    }
    if (st.empty()) return false;
    if (it == ')') {
      char ch = st.top();
      st.pop();
      if (ch != '(') return false;
    }
    if (it == ']') {
      char ch = st.top();
      st.pop();
      if (ch != '[') return false;
    }
    if (it == '}') {
      char ch = st.top();
      st.pop();
      if (ch != '{') return false;
    }
  }
  return st.empty();
}
bool comp(pair<long long int, string> &a, pair<long long int, string> &b) {
  if (b.first < a.first)
    return true;
  else if (b.first == a.first) {
    return (a.second < b.second);
  }
  return false;
}
void solve() {
  string s;
  cin >> s;
  long long int n;
  cin >> n;
  map<string, long long int> x;
  for (long long int i = 0; i < n; i++) {
    string name1, name2, temp, action, p;
    cin >> name1;
    cin >> action;
    if (action == "posted" || action == "commented") cin >> temp;
    cin >> name2 >> p;
    name2.pop_back();
    name2.pop_back();
    long long int points = 5;
    if (action == "posted") points = 15;
    if (action == "commented") points = 10;
    if (name1 == s) {
      x[name2] += points;
    } else if (name2 == s) {
      x[name1] += points;
    }
    x[name2] += 0;
    x[name1] += 0;
  }
  vector<pair<long long int, string>> ans;
  for (auto it : x) {
    if (it.first == s) continue;
    ans.push_back({it.second, it.first});
  }
  sort(ans.begin(), ans.end(), comp);
  for (auto it : ans) cout << it.second << "\n";
  return;
}
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  c_p_c();
  solve();
  return 0;
}