#include <bits/stdc++.h>   using namespace std;   int main() {     string org;     cin >> org;     int n;     cin >> n;     map<string, int> mp;     for (int i = 0; i < n; i++) {       string s, t;       cin >> s >> t;       string name;       string trash;       if (t[0] ==  p  || t[0] ==  c ) {         string trash;         cin >> trash;         cin >> name >> trash;         name.pop_back();         name.pop_back();         if (t[0] ==  p ) {           if (s == org)             mp[name] += 15;           else if (name == org)             mp[s] += 15;         } else {           if (s == org)             mp[name] += 10;           else if (name == org)             mp[s] += 10;         }       } else {         cin >> name >> trash;         name.pop_back();         name.pop_back();         if (s == org)           mp[name] += 5;         else if (name == org)           mp[s] += 5;       }       mp[s];       mp[name];     }     vector<pair<string, int>> v;     for (auto x : mp) {       if (x.first == org) continue;       v.emplace_back(x.first, x.second);     }     sort(v.begin(), v.end(), [](pair<string, int> p1, pair<string, int> p2) {       if (p1.second != p2.second) return p1.second > p2.second;       return p1.first < p2.first;     });     for (auto x : v) {       cout << x.first <<   n ;     }     return 0;   }   