#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main()
{
    FIO;
    int n,i,j;
    string temp;

    cin >> temp;
    cin >> n;

    temp+="'s";

    map <string,int> m;
    map <string,int> :: iterator it;

    for(j=0;j<n;j++){
        string a1,n2,tmp;

        cin >> a1 >> tmp;

        a1+="'s";

        if(tmp=="posted")
        {
            cin >> tmp >> n2 >> tmp;

            it=m.find(a1);

            if(it==m.end())
                m[a1]=-15;
            else
                it->second+=-15;

            it=m.find(n2);

            if(it==m.end())
                m[n2]=-15;
            else
                it->second+=-15;

        }else if(tmp=="commented"){

            cin >> tmp >> n2 >> tmp;

            it=m.find(a1);

            if(it==m.end())
                m[a1]=-10;
            else
                it->second+=-10;

            it=m.find(n2);

            if(it==m.end())
                m[n2]=-10;
            else
                it->second+=-10;

        }else{
            cin >> n2 >> tmp;

            it=m.find(a1);

            if(it==m.end())
                m[a1]=-5;
            else
                it->second+=-5;

            it=m.find(n2);

            if(it==m.end())
                m[n2]=-5;
            else
                it->second+=-5;

        }

    }

    std::vector<pair<int, string>> v ;

    for(it=m.begin();it!=m.end();it++){
        v.push_back(make_pair(it-> second,it->first));
    }

    sort(v.begin(),v.end());

    for(i=0;i<v.size();i++){
        if(v[i].second!=temp){
            j=0;
            while((v[i].second)[j]!=(char)39){
                cout << (v[i].second)[j];
                j++;
            }
            cout << endl;
        }
    }

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
//bool compare(const pair<string,ll> &p1, const pair<string,ll> &p2){
//    return p1.second>p2.second;
//}
int main(){
    string person;
    getline(cin,person);
    ll n;
    cin>>n;
    map<string,ll>m,val;
    val["likes"]=5;
    val["commented"]=10;
    val["posted"]=15;
    for(ll j=1;j<=n+1;j++){
        string s;
        getline(cin,s);
        string delimiter = " ";
        size_t pos = 0;
        string token;
        ll i=0;
        int flag=0;
        vector<string>v;
        string activity;
        while ((pos = s.find(delimiter)) != string::npos) {
            //cout<<"hi " ;
            token = s.substr(0, pos);
            if((i==2 && flag) || (i==3 && !flag)){
                string apdelimit="'s";
                if(token.substr(0,token.find(apdelimit)) != person && m.find(token.substr(0,token.find(apdelimit))) == m.end() )m[token.substr(0,token.find(apdelimit))]=0;
                v.push_back(token.substr(0,token.find(apdelimit)));

            }
            else if(i==0){
                v.push_back(token);
                if(token != person && m.find(token) == m.end()) m[token]=0;
            }
            if(i==1 && token=="likes") flag=1;
            if(i==1) activity=token;
            s.erase(0, pos+delimiter.length());
            i++;
        }
            int f=0;
            ll idx;
            for(ll i=0;i<v.size();i++){
                if(v[i]==person) {f=1;idx=i;}
            }
            for(ll i=0;i<v.size();i++){
                if(i!=idx && f){
                    m[v[i]]+=val[activity];
                }
            }
    }
    map<string,ll>:: iterator it;
    vector<pair<ll,string> >pp;
    for(it=m.begin();it!=m.end();++it){
        pp.push_back(make_pair(-it->second,it->first));
    }
    sort(pp.begin(),pp.end());
    for(ll i=0;i<pp.size();i++){
        cout<<pp[i].second<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool compare(const pair<string,ll> &p1, const pair<string,ll> &p2){
    return p1.second>p2.second;
}
int main(){
    string person;
    getline(cin,person);
    ll n;
    cin>>n;
    map<string,ll>m,val;
    val["likes"]=5;
    val["commented"]=10;
    val["posted"]=15;
    for(ll j=1;j<=n+1;j++){
        string s;
        getline(cin,s);
        string delimiter = " ";
        size_t pos = 0;
        string token;
        ll i=0;
        int flag=0;
        vector<string>v;
        string activity;
        while ((pos = s.find(delimiter)) != string::npos) {
            //cout<<"hi " ;
            token = s.substr(0, pos);
            if((i==2 && flag) || (i==3 && !flag)){
                string apdelimit="'s";
                if(token.substr(0,token.find(apdelimit)) != person && m.find(token.substr(0,token.find(apdelimit))) == m.end() )m[token.substr(0,token.find(apdelimit))]=0;
                v.push_back(token.substr(0,token.find(apdelimit)));

            }
            else if(i==0){
                v.push_back(token);
                if(token != person && m.find(token) == m.end()) m[token]=0;
            }
            if(i==1 && token=="likes") flag=1;
            if(i==1) activity=token;
            s.erase(0, pos+delimiter.length());
            i++;
        }
            int f=0;
            ll idx;
            for(ll i=0;i<v.size();i++){
                if(v[i]==person) {f=1;idx=i;}
            }
            for(ll i=0;i<v.size();i++){
                if(i!=idx && f){
                    m[v[i]]+=val[activity];
                }
            }
            map<string,ll>:: iterator it;
    }
    map<string,ll>:: iterator it;
    vector<pair<string,ll> >pp;
    for(it=m.begin();it!=m.end();++it){
        pp.push_back(make_pair(it->first,it->second));
    }
    sort(pp.begin(),pp.end(),compare);
    for(ll i=0;i<pp.size();i++){
        cout<<pp[i].first<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
//bool compare(const pair<string,ll> &p1, const pair<string,ll> &p2){
//    return p1.second>p2.second;
//}
int main(){
    string person;
    getline(cin,person);
    ll n;
    cin>>n;
    map<string,ll>m,val;
    val["likes"]=5;
    val["commented"]=10;
    val["posted"]=15;
    for(ll j=1;j<=n+1;j++){
        string s;
        getline(cin,s);
        string delimiter = " ";
        size_t pos = 0;
        string token;
        ll i=0;
        int flag=0;
        vector<string>v;
        string activity;
        while ((pos = s.find(delimiter)) != string::npos) {
            //cout<<"hi " ;
            token = s.substr(0, pos);
            if((i==2 && flag) || (i==3 && !flag)){
                string apdelimit="'s";
                if(token.substr(0,token.find(apdelimit)) != person && m.find(token.substr(0,token.find(apdelimit))) == m.end() )m[token.substr(0,token.find(apdelimit))]=0;
                v.push_back(token.substr(0,token.find(apdelimit)));

            }
            else if(i==0){
                v.push_back(token);
                if(token != person && m.find(token) == m.end()) m[token]=0;
            }
            if(i==1 && token=="likes") flag=1;
            if(i==1) activity=token;
            s.erase(0, pos+delimiter.length());
            i++;
        }
            int f=0;
            ll idx;
            for(ll i=0;i<v.size();i++){
                if(v[i]==person) {f=1;idx=i;}
            }
            for(ll i=0;i<v.size();i++){
                if(i!=idx && f){
                    m[v[i]]+=val[activity];
                }
            }
    }
    map<string,ll>:: iterator it;
    vector<pair<ll,string> >pp;
    for(it=m.begin();it!=m.end();++it){
        pp.push_back(make_pair(it->second,it->first));
    }
    sort(pp.begin(),pp.end());
    for(ll i=0;i<pp.size();i++){
        cout<<pp[i].first<<endl;
    }
}


#include <bits/stdc++.h>
#include<iostream>
#include<array>
using namespace std;
#define ps push_back
#define ll long long
#define vec vector<int>
#define vec2 vector<vector<int>>

int main(){
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif

	    ios_base::sync_with_stdio(false);
string s,s1,s2;
s="posted on";
s1="commented on";
s2="likes";
string S;
cin>>S;
int n;
cin>>n;
int k1=n+1;
map<string,int> map1;
while(k1--){
	string S1;
	getline(cin,S1);

	int check=0;
	int index=0;
	char to_get;
	for(int i=2;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,9)==s){
			check=1;
			index=i+11;
			to_get='p';

		}
		break;
	}
	}
	for(int i=2;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,12)==s1){
			check=1;
			index=i+14;
			to_get='c';

		}
		break;
	}
	}
	for(int i=2;i<S1.size();i++){
		if(S1[i]==' '){
			if(S1.substr(i+1,5)==s2){
			check=1;
			index=i+7;
			to_get='l';
		}
		break;
		}
	}
	if(check==1){
		int k=0;
		for(int i=0;i<S1.size();i++){
			if(S1[i]==' '){
				k=i;
				break;
			}
		}
		string s3=S1.substr(0,k);

		int check1=0;
		for(int i=index;i<S1.size();i++){
			if(S1[i]==' '){
				check1=i-2;
				break;
			}
		}
		string s4=S1.substr(index,check1-index);

	if(s3!=S){
			if(map1.count(s3)<1){
			if(to_get=='p')
				map1[s3]=15;
			else if(to_get=='c')
				map1[s3]=10;
			else if(to_get=='l')
				map1[s3]=5;
		}
	}
	if(s4!=S){
		if(map1.count(s4)<1){
			if(to_get='p')
				map1[s4]=15;
			else if(to_get=='c')
				map1[s4]=10;
			else if(to_get=='l')
				map1[s4]=5;
		}

		}
	}

}

set<pair<string,int>> set1;
auto it=map1.begin();
while(it!=map1.end())
{	//cout<<it->first<<" "<<it->second<<endl;
	set1.insert(make_pair(it->first,it->second));
	it++;

}

auto it1=set1.begin();
while(it1!=set1.end()){
	cout<<it1->first<<endl;
	it1++;
}

}


#include <bits/stdc++.h>
#include<iostream>
#include<array>
using namespace std;
#define ps push_back
#define ll long long
#define vec vector<int>
#define vec2 vector<vector<int>>

int main(){

	    ios_base::sync_with_stdio(false);
string s,s1,s2;
s="posted on";
s1="commented on";
s2="likes";
string S;
cin>>S;
int n;
cin>>n;
int k1=n+1;
map<string,int> map1;
map<pair<string,string>,int> map2;
while(k1--){
	string S1;
	getline(cin,S1);

	int check=0;
	int index=0;
	char to_get;
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,9)==s){
			check=1;
			index=i+11;
			to_get='p';

		}
		break;
	}
	}
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,12)==s1){
			check=1;
			index=i+14;
			to_get='c';

		}
		break;
	}
	}
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
			if(S1.substr(i+1,5)==s2){
			check=1;
			index=i+7;
			to_get='l';
		}
		break;
		}
	}
	if(check==1){
		int k=0;
		for(int i=0;i<S1.size();i++){
			if(S1[i]==' '){
				k=i;
				break;
			}
		}
		string s3=S1.substr(0,k);

		int check1=0;
		for(int i=index;i<S1.size();i++){
			if(S1[i]==' '){
				check1=i-2;
				break;
			}
		}
		string s4=S1.substr(index,check1-index);

		pair<string,string> p1;
		p1.first=s3;
		p1.second=s4;
		pair<string,string> p2;
		p2.first=s4;
		p2.second=s3;
		if(map2.count(p1)>0 || map2.count(p2)>0){
			if(p1.first==S){
				if(to_get=='p')
				map1[p1.second]=map1[p1.second]+15;

				else if(to_get=='c')
					map1[p1.second]=map1[p1.second]+10;
				else if(to_get=='l')
					map1[p1.second]=map1[p1.second]+5;
			}
			else if(p1.second==S){
				if(to_get=='p')
				map1[p1.first]=map1[p1.first]+15;

				else if(to_get=='c')
					map1[p1.first]=map1[p1.first]+10;
				else if(to_get=='l')
					map1[p1.first]=map1[p1.first]+5;
			}

			else{
				map1[p1.second]=0;
				map1[p1.first]=0;
			}
		}

		else{
			if(p1.first==S){
				if(to_get=='p')
				map1[p1.second]=15;

				else if(to_get=='c')
					map1[p1.second]=10;
				else if(to_get=='l')
					map1[p1.second]=5;

			}
			else if(p1.second==S){
				if(to_get=='p')
				map1[p1.first]=15;

				else if(to_get=='c')
					map1[p1.first]=10;
				else if(to_get=='l')
					map1[p1.first]=5;
			}

			else{
				map1[p1.second]=0;
				map1[p1.first]=0;
			}

			map2[p1]=1;
			map2[p2]=1;

		}

	}

}

vector<pair<int,string>> v;
auto it=map1.begin();
while(it!=map1.end())
{	//cout<<it->first<<" "<<it->second<<endl;
if(it->first==S){
	it++;
	continue;
}
v.push_back(make_pair(it->second,it->first));
	it++;

}
sort(v.begin(),v.end(),greater<pair<int,string>>());
map<int,int> map3;
for(int i=0;i<v.size();i++){
	int m=v[i].first;
	if(map3.count(m)>0)
		continue;
	map3[m]=1;
	set<pair<int,string>> set1;
	for(int j=0;j<v.size();j++){
		if(m==v[j].first){

			set1.insert(make_pair(m,v[j].second));
		}

	}

	auto it=set1.begin();
	while(it!=set1.end()){
		cout<<it->second<<endl;
		it++;
	}

}

}


#include <bits/stdc++.h>
#include<iostream>
#include<array>
using namespace std;
#define ps push_back
#define ll long long
#define vec vector<int>
#define vec2 vector<vector<int>>

int main(){
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif

	    ios_base::sync_with_stdio(false);
string s,s1,s2;
s="posted on";
s1="commented on";
s2="likes";
string S;
cin>>S;
int n;
cin>>n;
int k1=n+1;
map<string,int> map1;
map<pair<string,string>,int> map2;
while(k1--){
	string S1;
	getline(cin,S1);

	int check=0;
	int index=0;
	char to_get;
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,9)==s){
			check=1;
			index=i+11;
			to_get='p';

		}
		break;
	}
	}
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
		if(S1.substr(i+1,12)==s1){
			check=1;
			index=i+14;
			to_get='c';

		}
		break;
	}
	}
	for(int i=0;i<S1.size();i++){
		if(S1[i]==' '){
			if(S1.substr(i+1,5)==s2){
			check=1;
			index=i+7;
			to_get='l';
		}
		break;
		}
	}
	if(check==1){
		int k=0;
		for(int i=0;i<S1.size();i++){
			if(S1[i]==' '){
				k=i;
				break;
			}
		}
		string s3=S1.substr(0,k);

		int check1=0;
		for(int i=index;i<S1.size();i++){
			if(S1[i]==' '){
				check1=i-2;
				break;
			}
		}
		string s4=S1.substr(index,check1-index);

		pair<string,string> p1;
		p1.first=s3;
		p1.second=s4;
		pair<string,string> p2;
		p2.first=s4;
		p2.second=s3;
		if(map2.count(p1)>0 || map2.count(p2)>0){
			if(p1.first==S){
				if(to_get=='p')
				map1[p1.second]=map1[p1.second]+15;

				else if(to_get=='c')
					map1[p1.second]=map1[p1.second]+10;
				else if(to_get=='l')
					map1[p1.second]=map1[p1.second]+5;
			}
			else if(p1.second==S){
				if(to_get=='p')
				map1[p1.first]=map1[p1.first]+15;

				else if(to_get=='c')
					map1[p1.first]=map1[p1.first]+10;
				else if(to_get=='l')
					map1[p1.first]=map1[p1.first]+5;
			}

			else{

				if(map1.count(p1.second)<1)
					map1[p1.second]=0;
				if(map1.count(p1.first)<1)
					map1[p1.first]=0;
			}
		}

		else{
			if(p1.first==S){
				if(to_get=='p')
				map1[p1.second]=15;

				else if(to_get=='c')
					map1[p1.second]=10;
				else if(to_get=='l')
					map1[p1.second]=5;

			}
			else if(p1.second==S){
				if(to_get=='p')
				map1[p1.first]=15;

				else if(to_get=='c')
					map1[p1.first]=10;
				else if(to_get=='l')
					map1[p1.first]=5;
			}

			else{
				if(map1.count(p1.second)<1)
					map1[p1.second]=0;
				if(map1.count(p1.first)<1)
					map1[p1.first]=0;
			}

			map2[p1]=1;
			map2[p2]=1;

		}

	}

}

vector<pair<int,string>> v;
auto it=map1.begin();
while(it!=map1.end())
{	//cout<<it->first<<" "<<it->second<<endl;
if(it->first==S){
	it++;
	continue;
}
v.push_back(make_pair(it->second,it->first));
	it++;

}
sort(v.begin(),v.end(),greater<pair<int,string>>());
map<int,int> map3;
for(int i=0;i<v.size();i++){
	int m=v[i].first;
	if(map3.count(m)>0)
		continue;
	map3[m]=1;
	set<pair<int,string>> set1;
	for(int j=0;j<v.size();j++){
		if(m==v[j].first){

			set1.insert(make_pair(m,v[j].second));
		}

	}

	auto it=set1.begin();
	while(it!=set1.end()){
		cout<<it->second<<endl;
		it++;
	}

}

}


#include <bits/stdc++.h>
using namespace std;

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;

// template ends here
vector<string> removeDupWord(string str)
{
   vector<string> ans;
   string word = "";
   for (auto x : str)
   {
       if (x == ' ')
       {
		   ans.pb(word);
           //cout << word << endl;
           word = "";
       }
       else
       {
           word = word + x;
       }
   }
   ans.pb(word);
   //cout << word << endl;
   return ans;
}

void solve(){
	// code starts from here
	string nm;
	cin >> nm;

	map<string,int> mp;

	int N;
	cin >> N;
	char ch;

	for(int i = 0; i < N; i++){
		string str;
		//cin >> str;
		getline(cin >> ch,str);
		//getchar();
		reverse(all(str));
		str.pb(ch);
		reverse(all(str));
		//debug(str);
		vector<string> word = removeDupWord(str);
		int t = word.size();

		//debug(t);
		//for(int j = 0; j < t; j++){
			//debug(j);
			//debug(word[j]);
		//}
		string nm1 = word[0];
		string nm2 = word[t-2];
		nm2.pop_back();nm2.pop_back();

		mp[nm1] += 0;
		mp[nm2] += 0;

		if(nm1 == nm){
			if(word[1] == "posted") mp[nm2] += 15;
			else if(word[1] == "likes") mp[nm2] += 5;
			else mp[nm2] += 10;
		}
		if(nm2 == nm){
			if(word[1] == "posted") mp[nm1] += 15;
			else if(word[1] == "likes") mp[nm1] += 5;
			else mp[nm1] += 10;
		}
	}
	vector<pair<int,string>> ans;
	for(auto &p: mp){
		//cout << p.first << " " << -p.second << endl;
		if(p.first != nm) ans.pb(mp(-p.second,p.first));
	}
	sort(all(ans));
	//reverse(all(ans));
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i].second << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}

	//cout << getCurrentTime() << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;

// template ends here
vector<string> removeDupWord(string str)
{
   vector<string> ans;
   string word = "";
   for (auto x : str)
   {
       if (x == ' ')
       {
		   ans.pb(word);
           //cout << word << endl;
           word = "";
       }
       else
       {
           word = word + x;
       }
   }
   ans.pb(word);
   //cout << word << endl;
   return ans;
}

void solve(){
	// code starts from here
	string nm;
	cin >> nm;

	map<string,int> mp;

	int N;
	cin >> N;
	char ch;

	for(int i = 0; i < N; i++){
		string str;
		//cin >> str;
		getline(cin >> ch,str);
		//getchar();
		reverse(all(str));
		str.pb(ch);
		reverse(all(str));
		//debug(str);
		vector<string> word = removeDupWord(str);
		int t = word.size();

		//debug(t);
		//for(int j = 0; j < t; j++){
			//debug(j);
			//debug(word[j]);
		//}
		string nm1 = word[0];
		string nm2 = word[t-2];
		nm2.pop_back();nm2.pop_back();

		mp[nm1] += 0;
		mp[nm2] += 0;

		if(nm1 == nm){
			if(word[1] == "posted") mp[nm2] += 15;
			else if(word[1] == "likes") mp[nm2] += 5;
			else mp[nm2] += 10;
		}
		if(nm2 == nm){
			if(word[1] == "posted") mp[nm1] += 15;
			else if(word[1] == "likes") mp[nm1] += 5;
			else mp[nm1] += 10;
		}
	}
	vector<string> ans;
	for(auto &p: mp) if(p.first != nm) ans.pb(p.first);
	reverse(all(ans));
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}

	//cout << getCurrentTime() << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;

// template ends here
vector<string> removeDupWord(string str)
{
   vector<string> ans;
   string word = "";
   for (auto x : str)
   {
       if (x == ' ')
       {
		   ans.pb(word);
           //cout << word << endl;
           word = "";
       }
       else
       {
           word = word + x;
       }
   }
   ans.pb(word);
   //cout << word << endl;
   return ans;
}

void solve(){
	// code starts from here
	string nm;
	cin >> nm;

	map<string,int> mp;

	int N;
	cin >> N;
	char ch;

	for(int i = 0; i < N; i++){
		string str;
		//cin >> str;
		getline(cin >> ch,str);
		//getchar();
		reverse(all(str));
		str.pb(ch);
		reverse(all(str));
		//debug(str);
		vector<string> word = removeDupWord(str);
		int t = word.size();

		//debug(t);
		//for(int j = 0; j < t; j++){
			//debug(j);
			//debug(word[j]);
		//}
		string nm1 = word[0];
		string nm2 = word[t-2];
		nm2.pop_back();nm2.pop_back();

		mp[nm1] += 0;
		mp[nm2] += 0;

		if(nm1 == nm){
			if(word[1] == "posted") mp[nm2] += 15;
			else if(word[1] == "likes") mp[nm2] += 5;
			else mp[nm2] += 10;
		}
		if(nm2 == nm){
			if(word[1] == "posted") mp[nm1] += 15;
			else if(word[1] == "likes") mp[nm1] += 5;
			else mp[nm1] += 10;
		}
	}
	vector<string> ans;
	for(auto &p: mp) if(p.first != nm) ans.pb(p.first);
	//reverse(all(ans));
	for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();

	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}

	//cout << getCurrentTime() << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TIEMPO_CORRIDA cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";
#define FILES freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define FOR(i,a,b) for(i = a ; i < b ; i++)
#define RFOR(i,a,b) for(i = a ; i >= b ;i--)
#define FORSW(i,a,b,sw) for(i = a ; i < b && sw ; i++)
#define RFORSW(i,a,b,sw) for(i = a ; i >= b && sw ; i--)
#define fast ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define to_int(x) atoi(x.data())
#define to_long(x) atoll(x.data())
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,string> si;
const int modN = 1e9+7;
const double PI = 3.1415926535897932384626433832795028841;

int main(){
	//FILES
	string a,b,x,name;
	int n;
	while(cin  >> name >> n){
		map <string,int> m;
		while(n--){
			cin >> a >> x;
			m[a];
			if(x=="posted"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=15,m[b]+=15;
			}else if(x=="commented"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=10,m[b]+=10;
			}else{
				cin >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=5,m[b]+=5;
			}
			m[b];
		}
		vector<si> vec;
		si a;
		map<string,int> :: iterator it = m.begin();
		for(it;it!=m.end();it++){
			a = {-(it->second),it->first};
			vec.push_back(a);
		}
		sort(ALL(vec));
		FOR(n,0,vec.size()) if(vec[n].second!=name)cout<<vec[n].second<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TIEMPO_CORRIDA cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";
#define FILES freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define FOR(i,a,b) for(i = a ; i < b ; i++)
#define RFOR(i,a,b) for(i = a ; i >= b ;i--)
#define FORSW(i,a,b,sw) for(i = a ; i < b && sw ; i++)
#define RFORSW(i,a,b,sw) for(i = a ; i >= b && sw ; i--)
#define fast ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define to_int(x) atoi(x.data())
#define to_long(x) atoll(x.data())
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,string> si;
const int modN = 1e9+7;
const double PI = 3.1415926535897932384626433832795028841;

int main(){
	FILES
	string a,b,x,name;
	int n;
	while(cin  >> name >> n){
		map <string,int> m;
		while(n--){
			cin >> a >> x;
			m[a];
			if(x=="posted"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=15,m[b]+=15;
			}else if(x=="commented"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=10,m[b]+=10;
			}else{
				cin >> b >> x;
				b.erase(b.size()-2,2);
				if(a==name || b==name) m[a]+=5,m[b]+=5;
			}
			m[b];
		}
		vector<si> vec;
		si a;
		map<string,int> :: iterator it = m.begin();
		for(it;it!=m.end();it++){
			a = {-(it->second),it->first};
			vec.push_back(a);
		}
		sort(ALL(vec));
		FOR(n,0,vec.size()) if(vec[n].second!=name)cout<<vec[n].second<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TIEMPO_CORRIDA cerr << "tiempo: "<<1.0*clock()/CLOCKS_PER_SEC <<" seg.\n";
#define FILES freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define FOR(i,a,b) for(i = a ; i < b ; i++)
#define RFOR(i,a,b) for(i = a ; i >= b ;i--)
#define FORSW(i,a,b,sw) for(i = a ; i < b && sw ; i++)
#define RFORSW(i,a,b,sw) for(i = a ; i >= b && sw ; i--)
#define fast ios::sync_with_stdio(false),cin.tie(),cout.tie();
#define to_int(x) atoi(x.data())
#define to_long(x) atoll(x.data())
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,string> si;
const int modN = 1e9+7;
const double PI = 3.1415926535897932384626433832795028841;

int main(){
	//FILES
	string a,b,x,name;
	int n;
	while(cin  >> name >> n){
		map <string,int> m;
		while(n--){
			cin >> a >> x;
			if(x=="posted"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				m[a]+=15,m[b]+=15;
			}else if(x=="commented"){
				cin >> x >> b >> x;
				b.erase(b.size()-2,2);
				m[a]+=10,m[b]+=10;
			}else{
				cin >> b >> x;
				b.erase(b.size()-2,2);
				m[a]+=5,m[b]+=5;
			}
		}
		vector<si> vec;
		si a;
		map<string,int> :: iterator it = m.begin();
		for(it;it!=m.end();it++){
			a = {-(it->second),it->first};
			vec.push_back(a);
		}
		sort(ALL(vec));
		FOR(n,0,vec.size()) if(vec[n].second!=name)cout << vec[n].second<<"\n";
	}
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp; cin >> name; int n; cin >> n;
    while(getline(cin,s)){
        istringstream is(s);

        is>>s;
        if(1)
        {
            temp = s;
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }

            }else if(s == "commented")
            {

                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 10;}
                    if (temp == name)
                        {mm[temp2] += 10;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }else if(s == "likes")
            {

                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 5;}
                    if (temp == name)
                        {mm[temp2] += 5;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }
        }

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {
        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp, temp2; cin >> name; int n; cin >> n;
    int j = 0;
    getline(cin, s);
    while(j < n){
        getline(cin, s);
        temp = "";int i = 0;
        for ( i ; s[i] != ' '; i++)
        {
            temp += s[i];
        }
        i++;
        if(1)
        {
            if(s[i] == 'p')
            {
                for ( i; s[i] != ' '; i++);
                i += 4;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }

            }else if(s[i] == 'c')
            {

                for (i; s[i] != ' '; i++);
                i += 4;

                 temp2 = "";
                for ( i; s[i] != '\''; i++)
                {
                    temp2 += s[i];
                }

                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 10;}

                    if (temp == name)
                        {mm[temp2] += 10;}
                }
            }else if(s[i] == 'l')
            {
                for ( i; s[i] != ' '; i++);
                i++;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 5;}
                    if (temp == name)
                        {mm[temp2] += 5;}
                }
            }
        }
        s = "";
        j++;

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {

        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s %d\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp, temp2; cin >> name; int n; cin >> n;
    int j = 0;
    getline(cin, s);
    while(j < n){
        getline(cin, s);
        temp = "";int i = 0;
        for ( i ; s[i] != ' '; i++)
        {
            temp += s[i];
        }
        i++;
        if(1)
        {
            if(s[i] == 'p')
            {
                for ( i; s[i] != ' '; i++);
                i += 4;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }

            }else if(s[i] == 'c')
            {

                for (i; s[i] != ' '; i++);
                i += 4;

                 temp2 = "";
                for ( i; s[i] != '\''; i++)
                {
                    temp2 += s[i];
                }

                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 10;}

                    if (temp == name)
                        {mm[temp2] += 10;}
                }
            }else if(s[i] == 'l')
            {
                for ( i; s[i] != ' '; i++);
                i++;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 5;}
                    if (temp == name)
                        {mm[temp2] += 5;}
                }
            }
        }
        s = "";
        j++;

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {

        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp; cin >> name; int n; cin >> n;
    while(getline(cin,s)){
        istringstream is(s);

        is>>s;
        if(s != name)
        {
            temp = s;
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }

            }else if(s == "commented")
            {

                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 10;}
                    if (temp == name)
                        {mm[temp2] += 10;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }else if(s == "likes")
            {

                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 5;}
                    if (temp == name)
                        {mm[temp2] += 5;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }
        }else
        {
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "commented")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "likes")
            {
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }
        }

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {
        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;
char str[N];
int csum[N],n;
struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp; cin >> name; int n; cin >> n;
    while(getline(cin,s)){
        istringstream is(s);

        is>>s;
        if(s != name)
        {
            temp = s;
            is>>s;
            if(s == "posted")
            {
                mm[temp] += 15;
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "commented")
            {
                mm[temp] += 10;
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "likes")
            {
                mm[temp] += 5;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }
        }else
        {
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "commented")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "likes")
            {
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }
        }

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {
        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        printf("%s\n", pq.top().first.c_str());
        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp; cin >> name; int n; cin >> n;
    while(getline(cin,s)){
        istringstream is(s);

        is>>s;
        if(s != name)
        {
            temp = s;
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp2] += 15;}
                    if (temp == name)
                        {mm[temp] += 15;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }

            }else if(s == "commented")
            {

                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp2] += 10;}
                    if (temp == name)
                        {mm[temp] += 10;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }else if(s == "likes")
            {

                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp2] += 5;}
                    if (temp == name)
                        {mm[temp] += 5;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }
        }else
        {
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "commented")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "likes")
            {
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }
        }

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {
        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp, temp2; cin >> name; int n; cin >> n;
    int j = 0;
    getline(cin, s);
    while(j < n){
        getline(cin, s);
        temp = "";int i = 0;
        for ( i ; s[i] != ' '; i++)
        {
            temp += s[i];
        }
        i++;
        if(1)
        {
            if(s[i] == 'p')
            {
                for ( i; s[i] != ' '; i++);
                i += 4;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }

            }else if(s[i] == 'c')
            {

                for (i; s[i] != ' '; i++);
                i += 4;

                 temp2 = "";
                for ( i; s[i] != '\''; i++)
                {
                    temp2 += s[i];
                }

                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 10;}

                    if (temp == name)
                        {mm[temp2] += 10;}
                }
            }else if(s[i] == 'l')
            {
                for ( i; s[i] != ' '; i++);
                i++;
                 temp2 = "";
                for ( i ; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp]; mm[temp2];
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 5;}
                    if (temp == name)
                        {mm[temp2] += 5;}
                }
            }
        }
        s = "";
        j++;

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {

        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s %d\n", pq.top().first.c_str(), pq.top().second);
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
#include <stack>
const int N = 1e6 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define ll long long int
#ifdef _LOCAL_DEFINE
template <typename... T>
void debug(T &... args)
{
    ((cerr << args << " "), ...);
    cerr << endl;
}
#endif
using namespace std;
stack<pair<char,int> > s;

struct COMPARE {
  bool operator()(pair<string,int> const& P1, pair<string,int> const& P2)
    {
        if(P2.second != P1.second)
        {
            return P2.second > P1.second;
        }else
        {
            return P2.first < P1.first;
        }

    }
};

priority_queue<pair<string,int>,vector<pair<string,int>>,COMPARE >pq;

int main()
{

    map<string, int> mm;
    string s, name, temp; cin >> name; int n; cin >> n;
    while(getline(cin,s)){
        istringstream is(s);

        is>>s;
        if(s != name)
        {
            temp = s;
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp] += 15;}
                    if (temp == name)
                        {mm[temp2] += 15;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }

            }else if(s == "commented")
            {

                is>>s;
                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp2] += 10;}
                    if (temp == name)
                        {mm[temp] += 10;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }else if(s == "likes")
            {

                is>>s;
                string temp2 = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp2 += s[i];
                }
                mm[temp] = 0; mm[temp2] = 0;
                if (temp == name || temp2 == name) {
                    if (temp2 == name)
                        {mm[temp2] += 5;}
                    if (temp == name)
                        {mm[temp] += 5;}
                }else
                {
                    mm[temp] = 0; mm[temp2] = 0;
                }
            }
        }else
        {
            is>>s;
            if(s == "posted")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "commented")
            {
                is>>s;
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }else if(s == "likes")
            {
                is>>s;
                temp = "";
                for (int i = 0; s[i] != '\''; i++)
                {

                    temp += s[i];
                }
                if(temp != name)
                {
                    mm[temp];
                }
            }
        }

    }

    for (auto it = mm.begin(); it != mm.end(); it++)
    {
        pq.push(make_pair(it->first, it->second));
    }
    for (int i = 0; pq.size(); i++)
    {
        if(pq.top().first != name)
        {
            printf("%s\n", pq.top().first.c_str());
        }

        pq.pop();
    }
    #ifdef _LOCAL_DEFINE
    cerr << clock()*1.0/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second <= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		if (arr[1] == "posted")
		{
			if (arr[0] != name&&arr[2] == name)
				tmp[arr[0]] += 15;
			if (arr[2] != name&&arr[0] == name)
				tmp[arr[2]] += 15;
		}
		else if (arr[1] == "commented")
		{
			if (arr[0] != name&&arr[2] == name)
				tmp[arr[0]] += 10;
			if (arr[2] != name&&arr[0] == name)
				tmp[arr[2]] += 10;
		}
		else if (arr[1] == "likes")
		{
			if (arr[0] != name&&arr[2]==name)
				tmp[arr[0]] += 5;
			if (arr[2] != name&&arr[0]==name)
				tmp[arr[2]] += 5;
		}
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second <= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		int e = 0;
		if (arr[1] == "posted")
			e = 15;
		else if (arr[1] == "commented")
			e = 10;
		else if (arr[1] == "likes")
			e = 5;
		e = (name != arr[0] && arr[2] != name ? 0 : e);
		tmp[arr[0]] += e;
		tmp[arr[2]] += e;
	}
	tmp.erase(name);
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second <= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		int e = 0;
		if (arr[1] == "posted")
			e = 15;
		else if (arr[1] == "commented")
			e = 10;
		else if (arr[1] == "likes")
			e = 5;
		e = (name != arr[0] && arr[2] != name ? 0 : e);
		tmp[arr[0]] += e;
		tmp[arr[2]] += e;
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second >= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		if (arr[1] == "posted")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 15;
			if (arr[2] != name)
				tmp[arr[2]] += 15;
		}
		else if (arr[1] == "commented")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 10;
			if (arr[2] != name)
				tmp[arr[2]] += 10;
		}
		else if (arr[1] == "likes")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 5;
			if (arr[2] != name)
				tmp[arr[2]] += 5;
		}
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first >= b.first)
	{
		return a.second < b.second;
	}
	return a.second < b.second;
}

int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		if (arr[1] == "posted")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 15;
			if (arr[2] != name)
				tmp[arr[2]] += 15;
		}
		else if (arr[1] == "commented")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 10;
			if (arr[2] != name)
				tmp[arr[2]] += 10;
		}
		else if (arr[1] == "likes")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 5;
			if (arr[2] != name)
				tmp[arr[2]] += 5;
		}
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second <= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		if (arr[1] == "posted")
		{
			if (arr[0] != name&&arr[2] == name)
				tmp[arr[0]] += 15;
			else if (arr[2] != name&&arr[0] == name)
				tmp[arr[2]] += 15;
			else
				tmp[arr[0]] += 0, tmp[arr[2]] += 0;
		}
		else if (arr[1] == "commented")
		{
			if (arr[0] != name&&arr[2] == name)
				tmp[arr[0]] += 10;
			else if (arr[2] != name&&arr[0] == name)
				tmp[arr[2]] += 10;
			else
				tmp[arr[0]] += 0, tmp[arr[2]] += 0;
		}
		else if (arr[1] == "likes")
		{
			if (arr[0] != name&&arr[2]==name)
				tmp[arr[0]] += 5;
			else if (arr[2] != name&&arr[0]==name)
				tmp[arr[2]] += 5;
			else
				tmp[arr[0]] += 0, tmp[arr[2]] += 0;
		}
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;

#define all(v) 			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v) 			((int)((v).size()))
typedef long long ll;

void File()
{
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
}
void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int nn = 1e3 + 4;
const int oo = 0x3f3f3f3f;
bool fun(const pair<int, string>&a, const pair<int, string>&b)
{
	if (a.first > b.first)
		return 1;
	if (a.first < b.first)
		return 0;
	return a.second <= b.second;
}
int main()
{
	fast();
	string name;
	cin >> name;
	int n;
	cin >> n;
	map<string, int>tmp;
	for (int i = 0; i < n; i++)
	{
		string arr[4];
		for (int i = 0; i < 4; i++)
		{
			cin >> arr[i];
			if (i == 2 && (arr[1] == "posted" || arr[1] == "commented"))
				cin >> arr[i];
		}
		arr[2].pop_back();
		arr[2].pop_back();
		if (arr[1] == "posted")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 15;
			if (arr[2] != name)
				tmp[arr[2]] += 15;
		}
		else if (arr[1] == "commented")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 10;
			if (arr[2] != name)
				tmp[arr[2]] += 10;
		}
		else if (arr[1] == "likes")
		{
			if (arr[0] != name)
				tmp[arr[0]] += 5;
			if (arr[2] != name)
				tmp[arr[2]] += 5;
		}
	}
	vector<pair<int, string> >ans;
	for (auto it : tmp)
		ans.push_back(make_pair(it.second, it.first));
	sort(all(ans), fun);
	for (int i = 0; i < sz(ans); i++)
		cout << ans[i].second << endl;
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include <bits/stdc++.h>
//#include <cstdio>
using namespace std;
int main(){
    //freopen("in.txt", "r", stdin);
    //pair<int,string>p[300];
    vector<pair<int,string>>p;
    map<string,int>name;
    string me;
	int n,z=0,g=0;
    cin>>me>>n;
    for(int i=0; i<n; i++){
        string x,y,d,_;
		int po=-1;
        cin>>x>>d;
        if(d=="posted"){
			cin>>_>>y;
			po=15;
		}
        else if(d=="commented"){
			cin>>_>>y;
			po=10;
		}
        else{
			cin>>y;
			po=5;
		}
        y=y.substr(0,y.length()-2);
        cin>>_;
        //cout<<x<<" "<<d<<" "<<y<<"\n";
        if(x==me)
			name[y]+=po;
		else
			name[x]+=0;
        if(y==me)
			name[x]+=po;
		else
			name[y]+=0;
        /*
        int f=0;
        for(int q=0; q<=z; q++){
            if(p[q].second==x||p[q].second==y){p[q].first+=po,f=1;break;}
        }
        if(!f){
            if(x==me){p[z].first=po; p[z++].second=y;}
            else {p[z].first=0; p[z++].second=y;}
            if(y==me){p[z].first=po, p[z++].second=x;}
            else {p[z].first=0, p[z++].second=x;}
        }*/
    }
    for(auto c:name)
		p.push_back({-c.second,c.first});
    sort(p.begin(),p.end());
    for(auto c:p)
		cout<<c.second<<endl;
}


#include <iostream>
#include <algorithm>
#include <map>
//#include <cstdio>
using namespace std;
int main(){
    //freopen("in.txt", "r", stdin);
    //pair<int,string>p[300];
    vector<pair<int,string>>p;
    map<string,int>name;
    string me;
	int n,z=0,g=0;
    cin>>me>>n;
    for(int i=0; i<n; i++){
        string x,y,d,_;
		int po=-1;
        cin>>x>>d;
        if(d=="posted"){
			cin>>_>>y;
			po=15;
		}
        else if(d=="commented"){
			cin>>_>>y;
			po=10;
		}
        else{
			cin>>y;
			po=5;
		}
        y=y.substr(0,y.length()-2);
        cin>>_;
        //cout<<x<<" "<<d<<" "<<y<<"\n";
        if(x==me)
			name[y]+=po;
		else
			name[x]+=0;
        if(y==me)
			name[x]+=po;
		else
			name[y]+=0;
        /*
        int f=0;
        for(int q=0; q<=z; q++){
            if(p[q].second==x||p[q].second==y){p[q].first+=po,f=1;break;}
        }
        if(!f){
            if(x==me){p[z].first=po; p[z++].second=y;}
            else {p[z].first=0; p[z++].second=y;}
            if(y==me){p[z].first=po, p[z++].second=x;}
            else {p[z].first=0, p[z++].second=x;}
        }*/
    }
    for(auto c:name)
		p.push_back({-c.second,c.first});
    sort(p.begin(),p.end());
    for(auto c:p)
		cout<<c.second<<endl;
}


#include <bits/stdc++.h>
#include<string.h>
using namespace std;

int main() {

    string my_name;
    cin>>my_name;
    int n;
    cin>>n;
    map<string,int> M;

    while(n--)
    {
        string s;
        getline(cin,s);
        //cout<<s;

        string S;
       int i=0;

        for(i=0;s[i]!=' ';i++)
        {
            S+=s[i];
        }
        cout<<1;
        if(s[i+1]!='p')
        {
            i=i+11;
            string str;
            for(i;s[i]!=39;i++)
            str+=s[i];
            if(S==my_name)
            {
                M[str]+=15;
            }
            else if(str==my_name)
            M[S]+=15;

            else
            {
                if(M.find(S)==M.end())
                M[S]=0;
                if(M.find(str)==M.end())
                M[str]=0;
            }
        }
        else if(s[i+1]=='c')
        {

            i=i+14;
            string str;
            for(i;s[i]!=39;i++)
            str+=s[i];
            if(S==my_name)
            {
                M[str]+=10;
            }
            else if(str==my_name)
            M[S]+=10;
            else
            {
                if(M.find(S)==M.end())
                M[S]=0;
                if(M.find(str)==M.end())
                M[str]=0;
            }
        }
        else
        {

            i=i+7;
            string str;
            for(i;s[i]!=39;i++)
            str+=s[i];
            if(S==my_name)
            {
                M[str]+=55;
            }
            else if(str==my_name)
            M[S]+=5;
            else
            {
                if(M.find(S)==M.end())
                M[S]=0;
                if(M.find(str)==M.end())
                M[str]=0;
            }
        }

    }

    vector<pair<int,string> > v;
    for(auto it=M.begin();it!=M.end();it++)
    {
        v.push_back(make_pair(it->second,it->first));
    }
    sort(v.begin(),v.begin()+v.size());
    for(int l=0;l<v.size();l++)
    {
        cout<<v[l].second<<endl;
    }

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s,name;
   cin>>name;
   int n;
   cin>>n;
   cin.ignore();
   map<string,int> mp;
   for(int i=0;i<n;i++){
     getline(cin,s);

     stringstream ss{s};
     string arr[10];
     int k=0;
     while(ss>>arr[k]){
        k++;
     }
     if(arr[1]=="posted"){

        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[0]==name){

            mp[arr[3]]+=15;
        }else{
           mp[arr[3]];
        }

        if(arr[3]==name){
            mp[arr[0]]+=15;
        }else{
           mp[arr[0]];
        }
     }else if(arr[1]=="commented"){
         arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[0]==name){

            mp[arr[3]]+=10;

        }else{
            mp[arr[3]];
        }

        if(arr[3]==name){
           mp[arr[0]]+=10;
        }else{
           mp[arr[0]];
        }
     }else if(arr[1]=="likes"){
        arr[2]=arr[2].substr(0,(arr[2].length())-2);
        if(arr[0]==name){

           mp[arr[2]]+=5;
        }else{
           mp[arr[2]];
        }

        if(arr[2]==name){

           mp[arr[0]]+=5;
        }else{
           mp[arr[0]];
        }
     }
   }
   vector<pair<int,string>> vec;
   for(auto c:mp){
    vec.emplace_back(-c.second,c.first);
   }
   sort(vec.begin(),vec.end());
   for(int i=0;i<vec.size();i++){
    if(vec[i].second!=name){
      cout<<vec[i].second<<endl;
    }

   }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s,name;
   cin>>name;
   int n;
   cin>>n;
   cin.ignore();
   map<string,int> mp;
   for(int i=0;i<n;i++){
     getline(cin,s);

     stringstream ss{s};
     string arr[10];
     int k=0;
     while(ss>>arr[k]){
        k++;
     }
     if(arr[1]=="posted"){

        if(arr[0]!=name){
            mp[arr[0]]+=15;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=15;
        }
     }else if(arr[1]=="commented"){
        if(arr[0]!=name){
            mp[arr[0]]+=10;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=10;
        }
     }else if(arr[1]=="likes"){
        if(arr[0]!=name){
            mp[arr[0]]+=5;
        }
        arr[2]=arr[2].substr(0,(arr[2].length())-2);
        if(arr[2]!=name){
           mp[arr[2]]+=5;
        }
     }
   }
   for(c:mp){
    cout<<c.first<<endl;
   }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s,name;
   cin>>name;
   int n;
   cin>>n;
   cin.ignore();
   map<string,int> mp;
   for(int i=0;i<n;i++){
     getline(cin,s);

     stringstream ss{s};
     string arr[10];
     int k=0;
     while(ss>>arr[k]){
        k++;
     }
     if(arr[1]=="posted"){

        if(arr[0]!=name){
            mp[arr[0]]+=15;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=15;
        }
     }else if(arr[1]=="commented"){
        if(arr[0]!=name){
            mp[arr[0]]+=10;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=10;
        }
     }else if(arr[1]=="likes"){
        if(arr[0]!=name){
            mp[arr[0]]+=5;
        }
        arr[2]=arr[2].substr(0,(arr[2].length())-2);
        if(arr[2]!=name){
           mp[arr[2]]+=5;
        }
     }
   }
   vector<pair<int,string>> vec;
   for(auto c:mp){
    vec.emplace_back(-c.second,c.first);
   }
   sort(vec.begin(),vec.end());
   for(int i=0;i<vec.size();i++){
    cout<<vec[i].second<<endl;
   }
    return 0;
}

/*int ch[30];
   int n;
   long long cnt=0;
   string s;
   for(int i=0;i<26;i++){
      cin>>ch[i];
   }
   cin>>s;
   for(int i=0;i<s.length();i++){

   }*/


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   string s,name;
   cin>>name;
   int n;
   cin>>n;
   cin.ignore();
   map<string,int> mp;
   for(int i=0;i<n;i++){
     getline(cin,s);

     stringstream ss{s};
     string arr[10];
     int k=0;
     while(ss>>arr[k]){
        k++;
     }
     if(arr[1]=="posted"){

        if(arr[0]!=name){
            mp[arr[0]]+=15;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=15;
        }
     }else if(arr[1]=="commented"){
        if(arr[0]!=name){
            mp[arr[0]]+=10;
        }
        arr[3]=arr[3].substr(0,(arr[3].length())-2);
        if(arr[3]!=name){
           mp[arr[3]]+=10;
        }
     }else if(arr[1]=="likes"){
        if(arr[0]!=name){
            mp[arr[0]]+=5;
        }
        arr[2]=arr[2].substr(0,(arr[2].length())-2);
        if(arr[2]!=name){
           mp[arr[2]]+=5;
        }
     }
   }
   vector<pair<int,string>> vec;
   for(c:mp){
    vec.emplace_back(-c.second,c.first);
   }
   sort(vec.begin(),vec.end());
   for(int i=0;i<vec.size();i++){
    cout<<vec[i].second<<endl;
   }
    return 0;
}


#include<bits/stdc++.h>
#include<string>
#define ll long long
#define ld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    string a;
    cin>>a;
    ll n,i,j;
    cin>>n;
    map<string, ll> m;
    map<string, ll>::iterator it;
    for(i=0;i<n;i++)
    {
        string s,x,y="";
        cin>>s;
        x=s;
        cin>>s;
        if(s=="posted")
        {
            m[x]+=15;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=15;
        }
        else if(s=="commented")
        {
            m[x]+=10;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=10;
        }
        else
        {
            m[x]+=5;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=5;
        }
    }
    vector<pair<ll, string> > v;
    for(it=m.begin();it!=m.end();it++)
    {
        v.pb(mp(it->second, it->first));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(i=0;i<v.size();i++)
    {
        if(v[i].second!=a)
        cout<<v[i].second<<endl;
    }
}


#include<bits/stdc++.h>
#include<string>
#define ll long long
#define ld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    string a;
    cin>>a;
    ll n,i,j;
    cin>>n;
    map<string, ll> m;
    map<string, ll>::iterator it;
    for(i=0;i<n;i++)
    {
        string s,x,y="";
        cin>>s;
        x=s;
        cin>>s;
        if(s=="posted")
        {
            m[x]+=15;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=15;
        }
        else if(s=="commented")
        {
            m[x]+=10;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=10;
        }
        else
        {
            m[x]+=5;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=5;
        }
    }
    vector<pair<ll, string> > v;
    for(it=m.begin();it!=m.end();it++)
    {
        v.pb(mp(-1*it->second, it->first));
    }
    sort(v.begin(), v.end());
    //reverse(v.begin(), v.end());
    for(i=0;i<v.size();i++)
    {
        if(v[i].second!=a)
        cout<<v[i].second<<endl;
    }
}


#include<bits/stdc++.h>
#include<string>
#define ll long long
#define ld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    string a;
    cin>>a;
    ll n,i,j;
    cin>>n;
    map<string, ll> m;
    map<string, ll>::iterator it;
    for(i=0;i<n;i++)
    {
        string s,x,y="",z;
        cin>>s;
        x=s;
        cin>>s;
        ll flag=0;
        if(s=="posted")
        {
            flag=15;
            //m[x]+=15;
            cin>>s;
            cin>>s;
            z=s;
            for(j=0;j<z.size()-2;j++)
                y.pb(z[j]);
            cin>>s;
            //m[y]+=15;
        }
        else if(s=="commented")
        {
            flag=10;
            //m[x]+=10;
            cin>>s;
            cin>>s;
            z=s;
            for(j=0;j<z.size()-2;j++)
                y.pb(z[j]);
            cin>>s;
            //m[y]+=10;
        }
        else
        {
            flag=5;
            //m[x]+=5;
            cin>>s;
            z=s;
            for(j=0;j<z.size()-2;j++)
                y.pb(z[j]);
            cin>>s;
            //m[y]+=5;
        }
        if(x==a)
            m[y]+=flag;
        else
            m[x];
        if(y==a)
            m[x]+=flag;
        else
            m[y];
    }
    vector<pair<ll, string> > v;
    for(it=m.begin();it!=m.end();it++)
    {
        v.pb(mp(-it->second, it->first));
    }
    sort(v.begin(), v.end());
    //reverse(v.begin(), v.end());
    for(i=0;i<v.size();i++)
    {
        if(v[i].second!=a)
        cout<<v[i].second<<endl;
    }
}


#include<bits/stdc++.h>
#include<string>
#define ll long long
#define ld long double
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    string a;
    cin>>a;
    ll n,i,j;
    cin>>n;
    map<string, ll> m;
    map<string, ll>::iterator it;
    for(i=0;i<n;i++)
    {
        string s,x,y="";
        cin>>s;
        x=s;
        cin>>s;
        if(s=="posted")
        {
            m[x]+=15;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=15;
        }
        else if(s=="commented")
        {
            m[x]+=10;
            cin>>s;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=10;
        }
        else
        {
            m[x]+=5;
            cin>>s;
            x=s;
            for(j=0;j<x.size()-2;j++)
                y.pb(x[j]);
            cin>>s;
            m[y]+=5;
        }
    }
    vector<pair<ll, string> > v;
    for(it=m.begin();it!=m.end();it++)
    {
        v.pb(mp(it->second, it->first));
    }
    sort(v.begin(), v.end());
    for(i=0;i<v.size();i++)
    {
        if(v[i].second!=a)
        cout<<v[i].second<<endl;
    }
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool great( pair<string,int> &st , pair<string,int> &nd){
        return nd.second < st.second;
}
void sort(map<string, int>& M)
{
    vector<pair<string, int> > A;

    for (auto& it : M) {
        A.push_back(it);
    }
    sort(A.begin(), A.end(), great);
    for (auto& it : A) {
        cout << it.first  << endl;
    }
}

int main(void){
    string my_name;
    cin >> my_name;
    int loop = 0 ,last_siz = 0;
    cin >> loop;
    map <string,int> priority;
    while(loop--){
        string x;
        cin >> x;
        string cases;
        cin >> cases;
        if(cases == "likes"){
            string y ; cin >> y;
            string b ; cin >> b;
            y = y.substr(0,y.size()-2);
            if (x != my_name) priority[x] +=5;
            if (y != my_name) priority[y] +=5;
        }
        else{
            string a ; cin >> a;
            string y ; cin >> y;
            string b ; cin >> b;
            y = y.substr(0,y.size()-2);
            if (x != my_name) {
                if (cases == "posted"){
                    priority[x] +=15;
                }
                if (cases == "commented") {
                   priority[x] +=10;
                }
            }
            if (y != my_name) {
                if (cases == "posted"){
                    priority[y] +=15;
                }
                if (cases == "commented"){
                    priority[y] +=10;
                }
            }
        }
    }
    sort(priority);
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool great( pair<string,int> &st , pair<string,int> &nd){
        if (nd.second == st.second)
            return nd.first > st.first;
        else
            return nd.second < st.second;

}
void sort(map<string, int>& M)
{
    vector<pair<string, int> > A;

    for (auto& it : M) {
        A.push_back(it);
    }
    sort(A.begin(), A.end(), great);
    for (auto& it : A) {
        cout << it.first << endl;
    }
}

int main(void){
    string my_name;
    cin >> my_name;
    int loop = 0 ,last_siz = 0;
    cin >> loop;
    map <string,int> priority;
    while(loop--){
        string x;
        cin >> x;
        string cases;
        cin >> cases;
        if(cases == "likes"){
            string y ; cin >> y;
            string b ; cin >> b;
            y = y.substr(0,y.size()-2);
            if(x == my_name || y == my_name){
                if (x != my_name) priority[x] +=5;
                if (y != my_name) priority[y] +=5;
            }else{if (x != my_name) priority[x] +=0;
                if (y != my_name) priority[y] +=0;
                }
        }
        else{
            string a ; cin >> a;
            string y ; cin >> y;
            string b ; cin >> b;
            y = y.substr(0,y.size()-2);
            if(x == my_name || y == my_name){
                if (x != my_name) {
                    if (cases == "posted"){
                        priority[x] +=15;
                    }
                    if (cases == "commented") {
                       priority[x] +=10;
                    }
                }
                if (y != my_name) {
                    if (cases == "posted"){
                        priority[y] +=15;
                    }
                    if (cases == "commented"){
                        priority[y] +=10;
                    }
                }
            }else{if (x != my_name) priority[x] +=0;
                if (y != my_name) priority[y] +=0;
                }
        }
    }
    sort(priority);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp(pair<string,ll> x,pair<string,ll> y)
{
    if(x.second>y.second)return true;
    if(x.second<y.second)return false;
    return (x.first<y.first);
}
int main()
{
    map<string,ll> vec;
    string my_name;
    cin>>my_name;
    ll n,i,j,k,l;
    cin>>n;
    while(n--)
    {
        string action,name1,name2;
        getline(cin,action);
        while (action.length()==0 )
            getline(cin, action);
        for(i=0;i<action.length();i++)
        {
            if(action[i]==' ')break;
        }
        j=i;
        for(i=action.length()-1;i>=0;i--)
        {
            if(action[i]=='\'')
            {
                k=i;break;
            }
        }
        for(i=k;i>=0;i--)
        {
            if(action[i]==' ')break;
        }
        l=i;
        name1=action.substr(0,j);
        name2=action.substr(l+1,k-l-1);
        if(action[j+1]=='p')
        {
            if(name1==my_name)
            {
                vec[name2]+=15;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=15;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
        if(action[j+1]=='c')
        {
            if(name1==my_name)
            {
                vec[name2]+=10;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=10;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
        if(action[j+1]=='l')
        {
            if(name1==my_name)
            {
                vec[name2]+=5;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=5;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
    }
    vector<pair<string,ll>> v;
    for(auto j:vec)
    {
        v.push_back({j.first,j.second});
    }
    sort(v.begin(),v.end(),comp);
    for(auto j:v)
    {
        cout<<j.first<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp(pair<string,ll> x,pair<string,ll> y)
{
    return (x.first<y.first);
}
int main()
{
    map<string,ll> vec;
    string my_name;
    cin>>my_name;
    ll n,i,j,k,l;
    cin>>n;
    while(n--)
    {
        string action,name1,name2;
        getline(cin,action);
        while (action.length()==0 )
            getline(cin, action);
        for(i=0;i<action.length();i++)
        {
            if(action[i]==' ')break;
        }
        j=i;
        for(i=action.length()-1;i>=0;i--)
        {
            if(action[i]=='\'')
            {
                k=i;break;
            }
        }
        for(i=k;i>=0;i--)
        {
            if(action[i]==' ')break;
        }
        l=i;
        name1=action.substr(0,j);
        name2=action.substr(l+1,k-l-1);
        if(action[j+1]=='p')
        {
            if(name1==my_name)
            {
                vec[name2]+=15;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=15;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
        if(action[j+1]=='c')
        {
            if(name1==my_name)
            {
                vec[name2]+=10;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=10;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
        if(action[j+1]=='l')
        {
            if(name1==my_name)
            {
                vec[name2]+=5;continue;
            }
            if(name2==my_name)
            {
                vec[name1]+=5;continue;
            }
            vec[name1]+=0;
            vec[name2]+=0;
        }
    }
    vector<pair<string,ll>> v;
    for(auto j:vec)
    {
        v.push_back({j.first,j.second});
    }
    sort(v.begin(),v.end(),comp);
    for(auto j:v)
    {
        cout<<j.first<<"\n";
    }
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF INT_MAX
#define FIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define mod 1000000007ll
#define forn(i,n) for(int i=0;i<n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define forba(i,b,a) for(int i=b;i>=a;i--)
#define debx(x) cout << #x << ": " << x << endl
#define debxy(x,y) cout << #x << ": " << x << ' ' << #y << ": " << y << endl
#define YESp cout << "YES" << endl
#define NOp cout << "NO" << endl
#define Yesp cout << "Yes" << endl
#define Nop cout << "No" << endl
#define write(a) cout << a << endl
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pq priority_queue

ll fast_exp(ll base, ll power){ll ans=1;while(power){if(power&1)ans=(ans*base)%mod;base=(base*base)%mod;power=power>>1;}return ans%mod;}
ll modInv(ll a,ll p){return fast_exp(a,p-2)%p;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b,b%a);}
ll modFact(ll n){if(n>=mod)return 0;ll result=1;for(ll i = 1; i <= n; i++)result=(result*i)%mod;return result;}

pii moves[] = {{-1, 0}, {1, 0}, {0 ,-1}, {0, 1}};

/****** S ****** X ****** T ****** Y ****** A ****** M ******/

bool same(string s1,  string s2) {
    if(s1.length() != s2.length()) return false;
    forn(i, s1.length()) if(s1[i] != s2[i]) return false;
    return true;
}

int main() {
    FIO
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    string me;
    int n, add;
    map<string, int>  mp;
    cin >> me >> n;
    string name, name2, s;
    forn(i, n) {
        cin >> name >> s;
        if(s[0] == 'p') add = 15;
        else if(s[0] == 'c') add = 10;
        else add = 5;
        if(s[0] == 'p' || s[0] == 'c') cin >> s;
        cin >> name2;
        name2 = name2.substr(0, name2.length() - 2);
        // debxy(i, name2);
        cin >> s;
        if(same(me, name)) mp[name2] += add;
        else if(same(me, name2)) mp[name] +=  add;
        else {
            // debx(i);
            mp[name] += 0;
            mp[name2] += 0;
        }
    }
    for(auto it : mp) write(it.ff);
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF INT_MAX
#define FIO ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define mod 1000000007ll
#define forn(i,n) for(int i=0;i<n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define forba(i,b,a) for(int i=b;i>=a;i--)
#define debx(x) cout << #x << ": " << x << endl
#define debxy(x,y) cout << #x << ": " << x << ' ' << #y << ": " << y << endl
#define YESp cout << "YES" << endl
#define NOp cout << "NO" << endl
#define Yesp cout << "Yes" << endl
#define Nop cout << "No" << endl
#define write(a) cout << a << endl
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pq priority_queue

ll fast_exp(ll base, ll power){ll ans=1;while(power){if(power&1)ans=(ans*base)%mod;base=(base*base)%mod;power=power>>1;}return ans%mod;}
ll modInv(ll a,ll p){return fast_exp(a,p-2)%p;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b,b%a);}
ll modFact(ll n){if(n>=mod)return 0;ll result=1;for(ll i = 1; i <= n; i++)result=(result*i)%mod;return result;}

pii moves[] = {{-1, 0}, {1, 0}, {0 ,-1}, {0, 1}};

/****** S ****** X ****** T ****** Y ****** A ****** M ******/

bool same(string s1,  string s2) {
    if(s1.length() != s2.length()) return false;
    forn(i, s1.length()) if(s1[i] != s2[i]) return false;
    return true;
}

struct myComp {
    bool operator()(pair<string, int> p1, pair<string, int> p2) {
        if(p1.ss < p2.ss) return true;
        else if(p1.ss > p2.ss) return false;
        else {
            int j = 0;
            while(j < min(p1.ff.length(), p2.ff.length())) {
                if(p1.ff[j] > p2.ff[j]) return true;
                else if(p1.ff[j] < p2.ff[j]) return false;
                j++;
            }
            if(p1.ff.length() > p2.ff.length()) return true;
            else return false;
        }
    }
};

int main() {
    FIO
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    string me;
    int n, add;
    map<string, int>  mp;
    cin >> me >> n;
    string name, name2, s;
    pq<pair<string, int>, vector<pair<string, int>>,  myComp> p;
    forn(i, n) {
        cin >> name >> s;
        if(s[0] == 'p') add = 15;
        else if(s[0] == 'c') add = 10;
        else add = 5;
        if(s[0] == 'p' || s[0] == 'c') cin >> s;
        cin >> name2;
        name2 = name2.substr(0, name2.length() - 2);
        // debxy(i, name2);
        cin >> s;
        if(same(me, name)) mp[name2] += add;
        else if(same(me, name2)) mp[name] +=  add;
        else {
            // debx(i);
            mp[name] += 0;
            mp[name2] += 0;
        }
    }
    for(auto it : mp) p.push(it);
    while(!p.empty()) {
        write(p.top().ff);
        p.pop();
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,j,k;
    j=0;
    string me,a,b,c;
    map< string,int>m;
    cin>>me>>n;
    for(int i=0; i<n; i++)
    {
        k=0;
        cin>>a>>b;
        if(b=="posted")
        {
            cin>>b;
            cin>>b;
            k=15;
        }
        else if(b=="commented")
        {
            cin>>b;
            cin>>b;
            k=10;
        }
        else if(b=="likes")
        {
            cin>>b;
            k=5;
        }
        b.erase(b.end()-2,b.end());
        cin>>c;
        if(a==me)
        {
            m[c]+=k;
        }
    if(c==me)
    {
        m[a]+=k;
    }
}

vector<pair <int,string> > v;

for(auto p:m)
{
    v.emplace_back(p.second,p.first);
}
sort(v.begin(),v.end(),greater<int>());
for(auto p:v)
{
    if(p.second!=me)
        cout<<p.second<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,j; j=0;
   string me,a,b,c;
   map< string,int>m;
   cin>>me>>n;
  string s[2*n];
for(int i=0;i<n;i++){
    cin>>a>>b;
    if(b=="posted"){cin>>b; cin>>b;}
    else if(b=="commented"){cin>>b; cin>>b;}
     else if(b=="likes"){cin>>b;}
      b.erase(b.end()-2,b.end());
    cin>>c;
    if(a!=me){s[j]=a; j++;}
      if(b!=me){s[j]=b; j++;}
}
for(int i=0;i<j;i++){
  if(m[s[i]]!=1)
       {cout<<s[i]<<endl;
       m[s[i]]=1;}
}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    string me,a,b,c;
    map< string,int>m;
    cin>>me>>n;
    for(int i=0; i<n; i++)
    {
        k=0;
        cin>>a>>b;
        if(b=="posted")
        {
            cin>>b;
            cin>>b;
            k=15;
        }
        else if(b=="commented")
        {
            cin>>b;
            cin>>b;
            k=10;
        }
        else if(b=="likes")
        {
            cin>>b;
            k=5;
        }
        b.erase(b.end()-2,b.end());
        cin>>c;
        if(a==me)
        {
            m[b]+=k;
        }
        else{m[b];}

    if(b==me)
    {
        m[a]+=k;}
        else{m[a];}

}

vector<pair <int,string> > v;

for(auto p:m)
{
    v.emplace_back(-p.second,p.first);
}
sort(v.begin(),v.end());
for(auto p:v)
{
    if(p.second!=me)
        cout<<p.second<<endl;
}
return 0;
}