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

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

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



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

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

Input

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

Output

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

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

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

Examples

Input

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


Output

fatma
mona


Input

aba
1
likes likes posted's post


Output

likes
posted

Solution (in JAVA):

Solution:

import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
public class Template {
	//static int cnt=0;
static Scanner sc=new Scanner(System.in);
	static ArrayList<Integer> v=new ArrayList();;
	static int max=0;
	static String f3="";
	//static long n=0;
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
	
	public static void main (String[] args) throws java.lang.Exception{
String name=sc.nextLine();
int n=sc.nextInt();
sc.nextLine();
ArrayList<String> names=new ArrayList();
int[] values=new int[30*n+1];
//Map<String,Integer> val=new HashMap();
for(int i=0;i<n;i++) {
	String[] arr=sc.nextLine().split("\\s");
	
	
	if(arr.length==4) {
		String frnd="";
		if(arr[0].equals(name)) {
			 frnd=arr[2].substring(0,arr[2].length()-2);
		}
		else if(arr[2].substring(0,arr[2].length()-2).equals(name)) {
			//System.out.println(arr[0]);
			frnd=arr[0].substring(0,(arr[0].length()));
		}
		else {
			
			frnd=arr[0].substring(0,arr[0].length());
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=5;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=5;
			}
			frnd=arr[2].substring(0,arr[2].length()-2);
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=5;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=5;
			}
			frnd="";
			
			
			
			
			
		}
			if(!frnd.equals("") &&names.contains(frnd)) {
				values[names.indexOf(frnd)]+=5;
			}
			else if(!frnd.equals("")) {
				names.add(frnd);
				values[names.size()-1]+=5;
			}
		}
	
	else if(arr.length==5 && arr[arr.length-1].equals("wall"))
	{
		String frnd="";
		if(arr[0].equals(name)) 
			 frnd=arr[3].substring(0,arr[3].length()-2);
		else if(arr[3].substring(0,arr[3].length()-2).equals(name))
			frnd=arr[0].substring(0,arr[0].length());
		
		else
		{
			frnd=arr[0].substring(0,arr[0].length());
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=15;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=15;
			}
			frnd=arr[3].substring(0,arr[3].length()-2);
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=15;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=15;
			}
			frnd="";
		}
		if(frnd!="" && names.contains(frnd)) {
			values[names.indexOf(frnd)]+=15;
		}
		else if(frnd!="") {
			names.add(frnd);
			values[names.size()-1]+=15;
		}
	}
	else {

		String frnd="";
		if(arr[0].equals(name)) 
			 frnd=arr[3].substring(0,arr[3].length()-2);
		else if(arr[3].substring(0,arr[3].length()-2).equals(name)) 
			frnd=arr[0].substring(0,arr[0].length());
		else {
			
			frnd=arr[0].substring(0,arr[0].length());
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=10;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=10;
			}
			frnd=arr[3].substring(0,arr[3].length()-2);
			if(names.contains(frnd)) {
				//values[names.indexOf(frnd)]+=10;
			}
			else {
				names.add(frnd);
				//values[names.size()-1]+=10;
			}
			frnd="";
			
			
			
			
		}
		if(names.contains(frnd) && frnd!="") {
			values[names.indexOf(frnd)]+=10;
		}
		else if(!frnd.equals("")) {
			names.add(frnd);
			values[names.size()-1]+=10;
		}
		
	}
}

	
	
	ArrayList<String>[] fin=new ArrayList[30*n+1];
	for(int i=0;i<=30*n;i++) {
		fin[i]=new ArrayList();
	}
	for(int i=0;i<names.size();i++) {
		int value=values[i];
		fin[value].add(names.get(i));
	}

for(int i=(30*n);i>=0;i--) {
	if(fin[i].size()>0) {
		ArrayList<String> prin=fin[i];
		//System.out.println(prin);
		for (int b= 0; b < prin.size(); b++) { 
            for (int j = b + 1; j < prin.size(); j++) { 
                if (prin.get(b).compareToIgnoreCase(prin.get(j)) 
                    > 0) { 
                    String temp = prin.get(b); 
                   prin.set(b, prin.get(j)); 
                    prin.set(j,  temp); 
                } 
            } 
        }
		for(int k=0;k<prin.size();k++) {
			System.out.println(prin.get(k));
		}
	}
}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public static int[][] matrixInp(int n,int m) {
		int[][] arr=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				arr[i][j]=sc.nextInt();
			}
		}
		return arr;
	}
	
	public static int reduceFraction(int a, int b)
	{
		int aa=a;
		if(a==0 || b==0)
			return Math.max(a, b);
		else {
			for(int i=2;i<=Math.min(a, b);i++) {
				if(a%i==0 && b%i==0) {
					a=a/i;
					b=b/i;
					i--;
				}
			}
			
			
		}
		
		return aa/a;
	}
	
	public static long sumDigits(long x) {
		String s=String.valueOf(x);
		//System.out.println(s+" "+sx+" "+x);
		long sum=0;
		for(int i=0;i<s.length();i++) {
			sum+=Long.parseLong(s.substring(i,i+1));
		}
		return sum;
	}
	
	
	public static int[] primeFactofNumb(int num) {
		int[] factors=new int[num+1];
		for(int j=2;j<=Math.sqrt(num);j++) {
			if(num%j==0) {
				factors[j]++;
			}
			while(num%j==0) {
				num=num/j;
			}
			
		}
		
		if(num>1)
			factors[num]++;
		return factors;
	}
	
	
	
	
	public static double nCr(long n, long r){ 
		if(n<r) {
			return 0;
		}
		long rfact=1, nfact=1, nrfact=1,temp1 = n-r ,temp2 = r; 
		if(r>n-r) 
		{ 
			temp1 =r; 
			temp2 =n-r; 
		} 
		for(long i=1;i<=n;i++) 
		{ 
			if(i<=temp2) 
			{ 
				rfact *= i; 
				nrfact *= i; 
			} 
			else if(i<=temp1) 
			{ 
				nrfact *= i; 
			} 
			nfact *= i; 
		} 
		return nfact/(double)(rfact*nrfact); 
	}
		
	
		
	

	
	
	

		
	
	
	
	
static long gcd(long a,long b) {
		
	
		if(b==0) {
		return a;
		}
			
		
	return gcd(b,a%b);
	
	}
	
	
	
	
	
	public static int s2i(String s) {
		return Integer.parseInt(s);
	}
	

	
	
	public static int LeastIntFn(int a,int b) {
		if((b%a)==0) {
			return (int)b/a;
		}
		return (int)(b/a)+1;
	}
	
	
	
	public static ArrayList<Long> arrInpLong(int n){
		ArrayList<Long> arr=new ArrayList();
		for(int i=0;i<n;i++) {
		arr.add(sc.nextLong());	
		}
		return arr;
	}
	public static ArrayList<String> arrInpStr(int n){
		ArrayList<String> arr=new ArrayList();
		for(int i=0;i<n;i++) {
					arr.add(sc.nextLine());	
		}
		return arr;
	}
	
	public static ArrayList<Integer> arrInpInt(int n){
		ArrayList<Integer> arr=new ArrayList();
		for(int i=0;i<n;i++) {
			int k=sc.nextInt();
			if(k>max)
				max=k;
		arr.add(k);	
		}
		return arr;
	}
	
	
	public static void printArrInt(ArrayList<Integer> arr) {
		for(int i=0;i<arr.size();i++) {
			System.out.print(arr.get(i)+" ");
	}	
		}
	
	
	public static int min(int a,int b,int c) {
		int min1=Math.min(a, b);
		return Math.min(min1,c);
	}
}