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.Closeable;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class FacetookPriorityWall implements Closeable {

    private Scanner in = new Scanner(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        String me = in.nextLine();
        int n = in.nextInt();
        in.nextLine();
        Set<String> names = new HashSet<>();
        names.add(me);
        List<Operation> operations = new ArrayList<>();
        while (n-- > 0) {
            Operation op = convert(in.nextLine());
            operations.add(op);
            names.add(op.from);
            names.add(op.to);
        }
        n = names.size();
        int[] scores = new int[n];
        String[] index = new String[n];
        Map<String, Integer> inverted = new HashMap<>();
        int idx = 0;
        for (String name : names) {
            index[idx] = name;
            inverted.put(name, idx);
            idx++;
        }
        for (Operation op : operations) {
            if (me.equals(op.from)) {
                scores[inverted.get(op.to)] += op.score();
            } else if (me.equals(op.to)) {
                scores[inverted.get(op.from)] += op.score();
            }
        }
        List<Person> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (i != inverted.get(me)) {
                list.add(new Person(index[i], scores[i]));
            }
        }
        list.sort(Comparator.naturalOrder());
        for (Person p : list) {
            out.println(p.name);
        }
    }

    private class Person implements Comparable<Person> {
        private String name;
        private int score;

        private Person(String name, int score) {
            this.name = name;
            this.score = score;
        }

        @Override
        public int compareTo(Person o) {
            int x = -Integer.compare(this.score, o.score);
            return x != 0 ? x : name.compareTo(o.name);
        }
    }

    private class Operation {
        private String from, to, action;

        private Operation(String from, String to, String action) {
            this.from = from;
            this.to = to;
            this.action = action;
        }

        private int score() {
            switch (action) {
                case "posted":
                    return 15;
                case "commented":
                    return 10;
                case "likes":
                    return 5;
            }
            return 0;
        }
    }

    private Operation convert(String line) {
        String from, to;
        String[] split = line.split("\\s+");
        from = split[0];
        if ("likes".equals(split[1])) {
            to = split[2].substring(0, split[2].length() - 2);
        } else {
            to = split[3].substring(0, split[3].length() - 2);
        }
        String operation = split[1];
        return new Operation(from, to, operation);
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        try (FacetookPriorityWall instance = new FacetookPriorityWall()) {
            instance.solve();
        }
    }
}