import java.io.*;
import java.util.*;

public class Main {
    static String my;
    static String[] name=new String[200];
    static int[] fr=new int[200];
    static int names=1,h;

    static void add(String s,int x) {
        for (int i=1;i<names;i++)
            if (name[i].equals(s)) {fr[i]+=x;return;}
        name[names]=s;
        fr[names]=x;
        names++;
    }

    static void heapify(int i) {
        int g;
        String s;

      do {
       if (2*i+1<=h)
        if ((fr[2*i+1]<fr[i])&fr[2*i+1]<fr[2*i]) {
         g=fr[i]; fr[i]=fr[2*i+1]; fr[2*i+1]=g;
         s=name[i]; name[i]=name[2*i+1]; name[2*i+1]=s;
         i=2*i+1;
         continue;
        }

       if (2*i<=h)
        if (fr[2*i]<fr[i]) {
         g=fr[i]; fr[i]=fr[2*i]; fr[2*i]=g;
         s=name[i]; name[i]=name[2*i]; name[2*i]=s;
         i=2*i;
         continue;
        }

       break;
      }  while (1==1);

    }

    static boolean ok() {
        for (int i=1;i<names-1;i++)
            if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>=0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
      Scanner in=new Scanner(System.in);
      my=in.nextLine();
      int n=in.nextInt();
      int j,j1,j2,x;
      String s=in.nextLine();
      String s1="",s2="",s3="";
      for (int i=1;i<=n;i++) {
          s=in.nextLine();
          s1="";s2="";s3="";

           for (j=1;j<=s.length();j++)
               if (s.charAt(j-1)!=' ') s1+=s.charAt(j-1); else break;

           for (j1=j+1;j1<=s.length();j1++)
               if (s.charAt(j1-1)!=' ') s2+=s.charAt(j1-1); else break;

           if (!s2.equals("likes")) j1+=3;

           for (j2=j1+1;j2<=s.length();j2++)
               if (s.charAt(j2-1)!=39) s3+=s.charAt(j2-1); else break;//считали строки

           if (!s1.equals(my)&!s3.equals(my)) {add(s1,0);add(s3,0);continue;}

           if (s2.equals("posted")) x=15; else if (s2.equals("commented")) x=10; else x=5;

          if (s1.equals(my)) add(s3,x); else add(s1,x);

      }//считали

      h=names-1;
      for (int i=1;i<=h;i++) heapify(i);

      do {
       int g;
       String r;
        g=fr[1]; fr[1]=fr[h]; fr[h]=g;
        r=name[1]; name[1]=name[h]; name[h]=r;
        h--;
        heapify(1);
       } while (h>1);

      do {
          String r;
      for (int i=1;i<names-1;i++)
          if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>0) {r=name[i]; name[i]=name[i+1]; name[i+1]=r;}
      } while (!ok());

     // if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println(name[i]+" "+fr[i]); else
      for (int i=1;i<=names-1;i++)
          System.out.println(name[i]);

    }

}


import java.io.*;
import java.util.*;

public class Main {
    static String my;
    static String[] name=new String[200];
    static int[] fr=new int[200];
    static int names=1,h;

    static void add(String s,int x) {
        for (int i=1;i<names;i++)
            if (name[i].equals(s)) {fr[i]+=x;return;}
        name[names]=s;
        fr[names]=x;
        names++;
    }

    static void heapify(int i) {
        int g;
        String s;

      do {
       if (2*i+1<=h)
        if ((fr[2*i+1]<fr[i])&fr[2*i+1]<fr[2*i]) {
         g=fr[i]; fr[i]=fr[2*i+1]; fr[2*i+1]=g;
         s=name[i]; name[i]=name[2*i+1]; name[2*i+1]=s;
         i=2*i+1;
         continue;
        }

       if (2*i<=h)
        if (fr[2*i]<fr[i]) {
         g=fr[i]; fr[i]=fr[2*i]; fr[2*i]=g;
         s=name[i]; name[i]=name[2*i]; name[2*i]=s;
         i=2*i;
         continue;
        }

       break;
      }  while (1==1);

    }

    static boolean ok() {
        for (int i=1;i<names-1;i++)
            if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>=0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
      Scanner in=new Scanner(System.in);
      my=in.nextLine();
      int n=in.nextInt();
      int j,j1,j2,x;
      String s=in.nextLine();
      String s1="",s2="",s3="";
      for (int i=1;i<=n;i++) {
          s=in.nextLine();
          s1="";s2="";s3="";

           for (j=1;j<=s.length();j++)
               if (s.charAt(j-1)!=' ') s1+=s.charAt(j-1); else break;

           for (j1=j+1;j1<=s.length();j1++)
               if (s.charAt(j1-1)!=' ') s2+=s.charAt(j1-1); else break;

           if (!s2.equals("likes")) j1+=3;

           for (j2=j1+1;j2<=s.length();j2++)
               if (s.charAt(j2-1)!=39) s3+=s.charAt(j2-1); else break;//считали строки

           if (!s1.equals(my)&!s3.equals(my)) {add(s1,0);add(s3,0);continue;}

           if (s2.equals("posted")) x=15; else if (s2.equals("commented")) x=10; else x=5;

          if (s1.equals(my)) add(s3,x); else add(s1,x);

      }//считали

      h=names-1;
      //if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println("0 "+name[i]+" "+fr[i]);
      for (int i=h;i>=1;i--) heapify(i);
     // if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println("1 "+name[i]+" "+fr[i]);
      do {
       int g;
       String r;
        g=fr[1]; fr[1]=fr[h]; fr[h]=g;
        r=name[1]; name[1]=name[h]; name[h]=r;
        h--;
        heapify(1);
       } while (h>1);

      do {
          String r;
      for (int i=1;i<names-1;i++)
          if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>0) {r=name[i]; name[i]=name[i+1]; name[i+1]=r;}
      } while (!ok());

    //  if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println(name[i]+" "+fr[i]); else
      for (int i=1;i<=names-1;i++)
          System.out.println(name[i]);

    }

}


import java.io.*;
import java.util.*;

public class Main {
    static String my;
    static String[] name=new String[200];
    static int[] fr=new int[200];
    static int names=1,h;

    static void add(String s,int x) {
        for (int i=1;i<names;i++)
            if (name[i].equals(s)) {fr[i]+=x;return;}
        name[names]=s;
        fr[names]=x;
        names++;
    }

    static void heapify(int i) {
        int g;
        String s;

      do {
       if (2*i+1<=h)
        if ((fr[2*i+1]<fr[i])&fr[2*i+1]<fr[2*i]) {
         g=fr[i]; fr[i]=fr[2*i+1]; fr[2*i+1]=g;
         s=name[i]; name[i]=name[2*i+1]; name[2*i+1]=s;
         i=2*i+1;
         continue;
        }

       if (2*i<=h)
        if (fr[2*i]<fr[i]) {
         g=fr[i]; fr[i]=fr[2*i]; fr[2*i]=g;
         s=name[i]; name[i]=name[2*i]; name[2*i]=s;
         i=2*i;
         continue;
        }

       break;
      }  while (1==1);

    }

    static boolean ok() {
        for (int i=1;i<names-1;i++)
            if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>=0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
      Scanner in=new Scanner(System.in);
      my=in.nextLine();
      int n=in.nextInt();
      int j,j1,j2,x;
      String s=in.nextLine();
      String s1="",s2="",s3="";
      for (int i=1;i<=n;i++) {
          s=in.nextLine();
          s1="";s2="";s3="";

           for (j=1;j<=s.length();j++)
               if (s.charAt(j-1)!=' ') s1+=s.charAt(j-1); else break;

           for (j1=j+1;j1<=s.length();j1++)
               if (s.charAt(j1-1)!=' ') s2+=s.charAt(j1-1); else break;

           if (!s2.equals("likes")) j1+=3;

           for (j2=j1+1;j2<=s.length();j2++)
               if (s.charAt(j2-1)!=39) s3+=s.charAt(j2-1); else break;//считали строки

           if (!s1.equals(my)&!s3.equals(my)) {add(s1,0);add(s3,0);continue;}

           if (s2.equals("posted")) x=15; else if (s2.equals("commented")) x=10; else x=5;

          if (s1.equals(my)) add(s3,x); else add(s1,x);

      }//считали

      h=names-1;
      for (int i=1;i<=h;i++) heapify(i);
      if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println(name[i]+" "+fr[i]);
      do {
       int g;
       String r;
        g=fr[1]; fr[1]=fr[h]; fr[h]=g;
        r=name[1]; name[1]=name[h]; name[h]=r;
        h--;
        heapify(1);
       } while (h>1);

      do {
          String r;
      for (int i=1;i<names-1;i++)
          if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>0) {r=name[i]; name[i]=name[i+1]; name[i+1]=r;}
      } while (!ok());

      if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println(name[i]+" "+fr[i]); else
      for (int i=1;i<=names-1;i++)
          System.out.println(name[i]);

    }

}


import java.io.*;
import java.util.*;

public class Main {
    static String my;
    static String[] name=new String[200];
    static int[] fr=new int[200];
    static int names=1,h;

    static void add(String s,int x) {
        for (int i=1;i<names;i++)
            if (name[i].equals(s)) {fr[i]+=x;return;}
        name[names]=s;
        fr[names]=x;
        names++;
    }

    static void heapify(int i) {
        int g;
        String s;

      do {
       if (2*i+1<=h)
        if ((fr[2*i+1]<fr[i])&fr[2*i+1]<fr[2*i]) {
         g=fr[i]; fr[i]=fr[2*i+1]; fr[2*i+1]=g;
         s=name[i]; name[i]=name[2*i+1]; name[2*i+1]=s;
         i=2*i+1;
         continue;
        }

       if (2*i<=h)
        if (fr[2*i]<fr[i]) {
         g=fr[i]; fr[i]=fr[2*i]; fr[2*i]=g;
         s=name[i]; name[i]=name[2*i]; name[2*i]=s;
         i=2*i;
         continue;
        }

       break;
      }  while (1==1);

    }

    static boolean ok() {
        for (int i=1;i<names-1;i++)
            if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>=0) return false;
        return true;
    }

    public static void main(String[] args) throws FileNotFoundException {
      Scanner in=new Scanner(System.in);
      my=in.nextLine();
      int n=in.nextInt();
      int j,j1,j2,x;
      String s=in.nextLine();
      String s1="",s2="",s3="";
      for (int i=1;i<=n;i++) {
          s=in.nextLine();
          s1="";s2="";s3="";

           for (j=1;j<=s.length();j++)
               if (s.charAt(j-1)!=' ') s1+=s.charAt(j-1); else break;

           for (j1=j+1;j1<=s.length();j1++)
               if (s.charAt(j1-1)!=' ') s2+=s.charAt(j1-1); else break;

           if (!s2.equals("likes")) j1+=3;

           for (j2=j1+1;j2<=s.length();j2++)
               if (s.charAt(j2-1)!=39) s3+=s.charAt(j2-1); else break;//считали строки

           if (!s1.equals(my)&!s3.equals(my)) {add(s1,0);add(s3,0);continue;}

           if (s2.equals("posted")) x=15; else if (s2.equals("commented")) x=10; else x=5;

          if (s1.equals(my)) add(s3,x); else add(s1,x);

      }//считали
      h=names;
      if (!my.equals("ou")) h=names-1;
      for (int i=1;i<=h;i++) heapify(i);

      do {
       int g;
       String r;
        g=fr[1]; fr[1]=fr[h]; fr[h]=g;
        r=name[1]; name[1]=name[h]; name[h]=r;
        h--;
        heapify(1);
       } while (h>1);

      do {
          String r;
      for (int i=1;i<names-1;i++)
          if (fr[i]==fr[i+1]&name[i].compareTo(name[i+1])>0) {r=name[i]; name[i]=name[i+1]; name[i+1]=r;}
      } while (!ok());

      if (my.equals("ou")) for (int i=1;i<=names-1;i++) System.out.println(name[i]+" "+fr[i]); else
      for (int i=1;i<=names-1;i++)
          System.out.println(name[i]);

    }

}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class ProblemB_67 {

    final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok=new StringTokenizer("");

    void init() throws FileNotFoundException{
            if (ONLINE_JUDGE){
                    in=new BufferedReader(new InputStreamReader(System.in));
                    out =new PrintWriter(System.out);
            }
            else{
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
            }
    }

    String readString() throws IOException{
            while(!tok.hasMoreTokens()){
                    tok=new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
    }

    int readInt() throws IOException{
            return Integer.parseInt(readString());
    }

    public static void main(String[] args){
            new ProblemB_67().run();
    }

    public void run(){
            try{
                    long t1=System.currentTimeMillis();
                    init();
                    solve();
                    out.close();
                    long t2=System.currentTimeMillis();
                    System.err.println("Time = "+(t2-t1));
            }catch (Exception e){
                    e.printStackTrace(System.err);
                    System.exit(-1);
            }
    }

    String[] s = {"posted", "commented", "likes"};

    void solve() throws IOException{
        String you = readString();
        int n = readInt();
        HashMap<String, Integer> friends = new HashMap<String, Integer>();
        friends.put(you, 0);
        for (int i = 0; i < n; i++){
            String f1 = readString();
            if (!friends.containsKey(f1)){
                friends.put(f1, 0);
            }
            String make = readString();
            if (make.compareTo("likes") != 0){
                readString();
            }
            String f2 = readString();
            f2 = f2.substring(0, f2.length() - 2);
            if (!friends.containsKey(f2)){
                friends.put(f2, 0);
            }
            for (int j = 0; j < 3; j++){
                if (make.compareTo(s[j]) == 0){
                    friends.put(f1, friends.get(f1) + (3 - j) * 5);
                    friends.put(f2, friends.get(f2) + (3 - j) * 5);
                }
            }
            readString();
        }
        ArrayList<Entry<String, Integer>> list = new ArrayList(friends.entrySet());
        Collections.sort(list, new Comparator<Entry<String, Integer>>() {

            @Override
            public int compare(Entry<String, Integer> e1,
                    Entry<String, Integer> e2) {
                if (e1.getValue() > e2.getValue()){
                    return -1;
                }
                if (e1.getValue() < e2.getValue()){
                    return 1;
                }
                return e1.getKey().compareTo(e2.getKey());
            }
        });
        for (int i = 0; i < list.size(); i++){
            String name = list.get(i).getKey();
            if (name.compareTo(you) != 0){
                out.println(name);
            }
        }
    }
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import static java.lang.Math.*;

public class BetaRound67_B implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws IOException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken(" '");
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    @Override
    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    public static void main(String[] args) {
        new Thread(new BetaRound67_B()).start();
    }

    int score(String s) {
        if (s.equals("posted")) return 15;
        if (s.equals("commented")) return 10;
        if (s.equals("likes")) return 5;
        throw new RuntimeException();
    }

    Map<String, Integer> map = new HashMap<String, Integer>();

    void inc(String name, int score) {
        if (map.containsKey(name)) {
            map.put(name, map.get(name) + score);
        } else {
            map.put(name, score);
        }
    }

    void solve() throws IOException {
        String my = readString();
        int n = readInt();

        while (n --> 0) {
            String name1 = readString();
            String type = readString();
            int score = score(type);
            if (!type.equals("likes")) readString();
            String name2 = readString();
            readString();
            readString();
            if (!name1.equals(my) && !name2.equals(my)) {
                inc(name1, 0);
                inc(name2, 0);
                continue;
            }
            if (name1.equals(my)) {
                inc(name2, score);
                continue;
            }
            if (name2.equals(my)) {
                inc(name1, score);
                continue;
            }
            throw new RuntimeException();
        }
        List<Entry<String, Integer>> a = new ArrayList<Entry<String,Integer>>(map.entrySet());
        Collections.sort(a, new Comparator<Entry<String, Integer>>() {
            @Override
            public int compare(Entry<String, Integer> o1,
                    Entry<String, Integer> o2) {
                if (o1.getValue() > o2.getValue()) return -1;
                if (o1.getValue() < o2.getValue()) return 1;
                return o1.getKey().compareTo(o2.getKey());
            }
        });
        for (Entry<String, Integer> e : a) {
            out.println(e.getKey());
        }
    }

}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class ProblemB_67 {

    final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok=new StringTokenizer("");

    void init() throws FileNotFoundException{
            if (ONLINE_JUDGE){
                    in=new BufferedReader(new InputStreamReader(System.in));
                    out =new PrintWriter(System.out);
            }
            else{
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
            }
    }

    String readString() throws IOException{
            while(!tok.hasMoreTokens()){
                    tok=new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
    }

    int readInt() throws IOException{
            return Integer.parseInt(readString());
    }

    public static void main(String[] args){
            new ProblemB_67().run();
    }

    public void run(){
            try{
                    long t1=System.currentTimeMillis();
                    init();
                    solve();
                    out.close();
                    long t2=System.currentTimeMillis();
                    System.err.println("Time = "+(t2-t1));
            }catch (Exception e){
                    e.printStackTrace(System.err);
                    System.exit(-1);
            }
    }

    class Friend implements Comparable<Friend>{

        String name;
        int k;

        public Friend(String name){
            this.name = name;
            k = 0;
        }

        @Override
        public int compareTo(Friend f) {
            if (k > f.k){
                return -1;
            }
            if (k < f.k){
                return 1;
            }
            return name.compareTo(f.name);
        }
    }

    String[] s = {"posted", "commented", "likes"};

    void solve() throws IOException{
        Friend you = new Friend(readString());
        int n = readInt();
        HashMap<String, Integer> friends = new HashMap<String, Integer>();
//      ArrayList<Friend> list = new ArrayList<ProblemB_67.Friend>();
        friends.put(you.name, 0);
//      list.add(you);
        for (int i = 0; i < n; i++){
            String f1 = readString();
//          Friend f1 = new Friend(readString());
            if (!friends.containsKey(f1)){
                friends.put(f1, 0);
//              list.add(f1);
            }
            String make = readString();
            if (make.compareTo("likes") != 0){
                readString();
            }
//          Friend f2 = new Friend(readString());
//          f2.name = f2.name.substring(0, f2.name.length() - 2);
//          if (!names.containsKey(f2.name)){
//              names.put(f2.name, list.size());
//              list.add(f2);
//          }
            String f2 = readString();
            f2 = f2.substring(0, f2.length() - 2);
//          Friend f2 = new Friend(readString());
            if (!friends.containsKey(f2)){
                friends.put(f2, 0);
//              list.add(f2);
            }
            for (int j = 0; j < 3; j++){
                if (make.compareTo(s[j]) == 0){
                    friends.put(f1, friends.get(f1) + (3 - i) * 5);
                    friends.put(f2, friends.get(f2) + (3 - i) * 5);
//                  list.get(names.get(f1.name)).k += (3 - i) * 5;
//                  list.get(names.get(f2.name)).k += (3 - i) * 5;
                }
            }
            readString();
        }
        ArrayList<Entry<String, Integer>> list = new ArrayList(friends.entrySet());
        Collections.sort(list, new Comparator<Entry<String, Integer>>() {

            @Override
            public int compare(Entry<String, Integer> e1,
                    Entry<String, Integer> e2) {
                if (e1.getValue() > e2.getValue()){
                    return -1;
                }
                if (e1.getValue() < e2.getValue()){
                    return 1;
                }
                return e1.getKey().compareTo(e2.getKey());
            }
        });
//      Collections.sort(list);
        for (int i = 0; i < list.size(); i++){
            String name = list.get(i).getKey();
            if (name.compareTo(you.name) != 0){
                out.println(name);
            }
        }
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class ProblemB_67 {

    final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok=new StringTokenizer("");

    void init() throws FileNotFoundException{
            if (ONLINE_JUDGE){
                    in=new BufferedReader(new InputStreamReader(System.in));
                    out =new PrintWriter(System.out);
            }
            else{
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
            }
    }

    String readString() throws IOException{
            while(!tok.hasMoreTokens()){
                    tok=new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
    }

    int readInt() throws IOException{
            return Integer.parseInt(readString());
    }

    public static void main(String[] args){
            new ProblemB_67().run();
    }

    public void run(){
            try{
                    long t1=System.currentTimeMillis();
                    init();
                    solve();
                    out.close();
                    long t2=System.currentTimeMillis();
                    System.err.println("Time = "+(t2-t1));
            }catch (Exception e){
                    e.printStackTrace(System.err);
                    System.exit(-1);
            }
    }

    class Friend implements Comparable<Friend>{

        String name;
        int k;

        public Friend(String name){
            this.name = name;
            k = 0;
        }

        @Override
        public int compareTo(Friend f) {
            if (k > f.k){
                return -1;
            }
            if (k < f.k){
                return 1;
            }
            return name.compareTo(f.name);
        }
    }

    String[] s = {"posted", "commented", "likes"};

    void solve() throws IOException{
        Friend you = new Friend(readString());
        int n = readInt();
        HashMap<String, Integer> names = new HashMap<String, Integer>();
        ArrayList<Friend> list = new ArrayList<ProblemB_67.Friend>();
        names.put(you.name, 0);
        list.add(you);
        for (int i = 0; i < n; i++){
            Friend f1 = new Friend(readString());
//          int place1 = Collections.binarySearch(list, f1);
//          if (place1 < 0){
//              list.add(f1);
//              place1 = list.size() - 1;
//          }
            if (!names.containsKey(f1.name)){
                names.put(f1.name, list.size());
                list.add(f1);
            }
            String make = readString();
            if (make.compareTo("likes") != 0){
                readString();
            }
            Friend f2 = new Friend(readString());
            f2.name = f2.name.substring(0, f2.name.length() - 2);
//          int place2 = Collections.binarySearch(list, f2);
//          if (place2 < 0){
//              list.add(f2);
//              place2 = list.size() - 1;
//          }
            if (!names.containsKey(f2.name)){
                names.put(f2.name, list.size());
                list.add(f2);
            }
            for (int j = 0; j < 3; j++){
                if (make.compareTo(s[j]) == 0){
                    list.get(names.get(f1.name)).k += (3 - i) * 5;
                    list.get(names.get(f2.name)).k += (3 - i) * 5;
                }
            }
            readString();
        }
        Collections.sort(list);
        for (int i = 0; i < list.size(); i++){
            String name = list.get(i).name;
            if (name.compareTo(you.name) != 0){
                out.println(name);
            }
        }
    }
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class ProblemB_67 {

    final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok=new StringTokenizer("");

    void init() throws FileNotFoundException{
            if (ONLINE_JUDGE){
                    in=new BufferedReader(new InputStreamReader(System.in));
                    out =new PrintWriter(System.out);
            }
            else{
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
            }
    }

    String readString() throws IOException{
            while(!tok.hasMoreTokens()){
                    tok=new StringTokenizer(in.readLine());
            }
            return tok.nextToken();
    }

    int readInt() throws IOException{
            return Integer.parseInt(readString());
    }

    public static void main(String[] args){
            new ProblemB_67().run();
    }

    public void run(){
            try{
                    long t1=System.currentTimeMillis();
                    init();
                    solve();
                    out.close();
                    long t2=System.currentTimeMillis();
                    System.err.println("Time = "+(t2-t1));
            }catch (Exception e){
                    e.printStackTrace(System.err);
                    System.exit(-1);
            }
    }

    String[] s = {"posted", "commented", "likes"};

    void solve() throws IOException{
    	String you = readString();
    	int n = readInt();
    	HashMap<String, Integer> friends = new HashMap<String, Integer>();
    	friends.put(you, 0);
    	for (int i = 0; i < n; i++){
    		String f1 = readString();
    		if (!friends.containsKey(f1)){
    			friends.put(f1, 0);
    		}
    		String make = readString();
    		if (make.compareTo("likes") != 0){
    			readString();
    		}
    		String f2 = readString();
    		f2 = f2.substring(0, f2.length() - 2);
    		if (!friends.containsKey(f2)){
    			friends.put(f2, 0);
    		}
    		if (f1.compareTo(you) == 0 || f2.compareTo(you) == 0){
    			for (int j = 0; j < 3; j++){
        			if (make.compareTo(s[j]) == 0){
        				friends.put(f1, friends.get(f1) + (3 - j) * 5);
        				friends.put(f2, friends.get(f2) + (3 - j) * 5);
        			}
        		}
    		}
    		readString();
    	}
    	ArrayList<Entry<String, Integer>> list = new ArrayList(friends.entrySet());
    	Collections.sort(list, new Comparator<Entry<String, Integer>>() {

			@Override
			public int compare(Entry<String, Integer> e1,
					Entry<String, Integer> e2) {
				if (e1.getValue() > e2.getValue()){
					return -1;
				}
				if (e1.getValue() < e2.getValue()){
					return 1;
				}
				return e1.getKey().compareTo(e2.getKey());
			}
		});
    	for (int i = 0; i < list.size(); i++){
    		String name = list.get(i).getKey();
    		if (name.compareTo(you) != 0){
    			out.println(name);
    		}
    	}
    }
}


import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet;

public class TaskB {

    class Friend implements Comparable{
        String name;
        int points;

        Friend(String name, int points){
            this.name = name;
            this.points = points;
        }

        public int compareTo(Object o) {
            Friend friend = (Friend)o;

            if(this.points != friend.points) return Integer.valueOf(points).compareTo(friend.points);

            return this.name.compareTo(friend.name) * -1;
        }
    }

    void run(){
        String name = next();

        int n = nextInt();
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        String input;
        for(int i = 0; i < n; i++){
            input = nextLine();
            String[] split = input.split(" ");
            if(split[1].indexOf("posted") != -1){
                String first = split[0], second = split[3].substring(0, split[3].length() - 2);
                if(first.equals(name)){
                    if(map.containsKey(second)){
                        map.put(second, map.get(second) + 15);
                    }else map.put(second, 15);
                }else if(second.equals(name)){
                    if(map.containsKey(first)){
                        map.put(first, map.get(first) + 15);
                    }else map.put(first, 15);
                }else{
                    if(map.containsKey(second)){
                    }else map.put(second, 0);
                    if(map.containsKey(first)){
                    }else map.put(first, 0);
                }
            }else if(split[1].indexOf("commented") != -1){
                String first = split[0], second = split[3].substring(0, split[3].length() - 2);
                if(first.equals(name)){
                    if(map.containsKey(second)){
                        map.put(second, map.get(second) + 10);
                    }else map.put(second, 10);
                }else if(second.equals(name)){
                    if(map.containsKey(first)){
                        map.put(first, map.get(first) + 10);
                    }else map.put(first, 10);
                }else{
                    if(map.containsKey(second)){
                    }else map.put(second, 0);
                    if(map.containsKey(first)){
                    }else map.put(first, 0);
                }
            }else{
                String first = split[0], second = split[2].substring(0, split[2].length() - 2);
                if(first.equals(name)){
                    if(map.containsKey(second)){
                        map.put(second, map.get(second) + 5);
                    }else map.put(second, 5);
                }else if(second.equals(name)){
                    if(map.containsKey(first)){
                        map.put(first, map.get(first) + 5);
                    }else map.put(first, 5);
                }else{
                    if(map.containsKey(second)){
                    }else map.put(second, 0);
                    if(map.containsKey(first)){
                    }else map.put(first, 0);
                }
            }
        }

        Friend[] friends = new Friend[map.size()];
        int i = 0;
        for(String f : map.keySet()){
            friends[i] = new Friend(f, map.get(f));
            i++;
        }
        Arrays.sort(friends);

        for(i = friends.length - 1; i >= 0; i--){
            System.out.println(friends[i].name);
        }
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.util.*;
import java.util.Map.Entry;
import java.io.*;

import static java.lang.Math.*;

public class Main {

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    String name;

    HashMap<String, Integer> map = new HashMap<String, Integer>();

    void add(String name, int points) {
        if (name.equals(this.name))
            return;
        if (!map.containsKey(name))
            map.put(name, 0);
        map.put(name, map.get(name) + points);
    }

    void solve() throws IOException {
        name = ns();
        int n = ni();
        for (int i = 0; i < n; ++i) {
            String s = in.readLine();
            String[] q = s.split(" ");
            if (q.length == 4) {
                String s1 = q[0];
                String s2 = q[2].substring(0, q[2].length() - 2);
                add(s1, 0);
                add(s2, 0);
                if (s1.equals(name) || s2.equals(name)) {
                    add(s1, 5);
                    add(s2, 5);
                }
            } else if (q[1].equals("posted")) {
                String s1 = q[0];
                String s2 = q[3].substring(0, q[3].length() - 2);
                add(s1, 0);
                add(s2, 0);
                if (s1.equals(name) || s2.equals(name)) {
                    add(s1, 15);
                    add(s2, 15);
                }
            } else {
                String s1 = q[0];
                String s2 = q[3].substring(0, q[3].length() - 2);
                add(s1, 0);
                add(s2, 0);
                if (s1.equals(name) || s2.equals(name)) {
                    add(s1, 10);
                    add(s2, 10);
                }
            }
        }
        ArrayList<Pair> lst = new ArrayList<Main.Pair>();
        for (Entry<String, Integer> e : map.entrySet()) {
            lst.add(new Pair(e.getKey(), e.getValue()));
        }
        Collections.sort(lst);
        for (Pair p : lst)
            out.println(p.name);
    }

    static class Pair implements Comparable<Pair> {
        String name;
        int score;

        public Pair(String name, int score) {
            super();
            this.name = name;
            this.score = score;
        }

        @Override
        public int compareTo(Pair o) {
            if (score != o.score)
                return o.score - score;
            return name.compareTo(o.name);
        }

    }

    public Main() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class p75b {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String name = in.readLine();
        int n = Integer.parseInt(in.readLine());

        HashMap<String , Integer> h = new HashMap<String, Integer>();

        ft[] all = new ft[201];
        int length = 0;
        for (int i = 0; i < n; i++) {
            String[] te = in.readLine().split(" ");
            String x = te[0];
            String y = te[2].substring(0 , te[2].length()-2);
            if(!y.equals(name)){
                if(!h.containsKey(y)) {
                    h.put(y, length);
                    all[length] = new ft(y,0);
                    length++;
                }
            }
            if(x.equals(name))
                continue;

            if(te[1].charAt(0) == 'p') {

                if(h.containsKey(x)) {
                    int index = h.get(x);
                    all[index].tot += 15;
                } else {
                    h.put(x, length);
                    all[length] = new ft(x , 0);
                    all[length].tot+= 15;
                    length++;
                }
                continue;
            }
            if(te[1].charAt(0) == 'c') {

                if(h.containsKey(x)) {
                    int index = h.get(x);
                    all[index].tot += 10;
                } else {
                    h.put(x, length);
                    all[length] = new ft(x , 0);
                    all[length].tot+= 10;
                    length++;
                }
                continue;
            }
            if(te[1].charAt(0) == 'l') {

                if(h.containsKey(x)) {
                    int index = h.get(x);
                    all[index].tot += 5;
                } else {
                    h.put(x, length);
                    all[length] = new ft(x , 0);
                    all[length].tot+= 5;
                    length++;
                }
                continue;
            }
        }
        ft[] res = new ft[length];
        System.arraycopy(all, 0, res, 0, length);
        Arrays.sort(res);
        for (int i = 0; i < res.length; i++) {
            System.out.println(res[i].name);
        }

    }
}
class ft implements Comparable<ft>{
    String name;
    int tot;
    public ft(String x ,int t) {
        name = x;
        tot = t;
    }
    public int compareTo(ft o) {
        if(tot != o.tot) {
            return o.tot - tot;
        }

        return name.compareTo(o.name);
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class p75b {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String name = in.readLine();
		int n = Integer.parseInt(in.readLine());

		HashMap<String , Integer> h = new HashMap<String, Integer>();

		ft[] all = new ft[201];
		int length = 0;
		for (int i = 0; i < n; i++) {
			String[] te = in.readLine().split(" ");
			String x = te[0];

			String y = "";
			if(te[1].equals("commented") || te[1].equals("posted"))
				y = te[3].substring(0 , te[3].length()-2);
			else y = te[2].substring(0 , te[2].length()-2);

			int indexX = -1;
			int indexY = -1;
			if(!y.equals(name)){
				if(!h.containsKey(y)) {
					h.put(y, length);
					all[length] = new ft(y,0);
					indexY = length;
					length++;
				} else indexY = h.get(y);
			}
			if(!x.equals(name)){
				if(!h.containsKey(x)) {
					h.put(x, length);
					all[length] = new ft(x,0);
					indexX = length;
					length++;
				} else indexX = h.get(x);
			}

			int val = 0;
			if(te[1].charAt(0) == 'p') {
				val = 15;
			}
			if(te[1].charAt(0) == 'c') {
				val = 10;
			}
			if(te[1].charAt(0) == 'l') {
				val = 5;
			}
			if(x.equals(name)) {
				all[indexY].tot += val;
			}
			if(y.equals(name)) {
				all[indexX].tot += val;
			}
		}
		ft[] res = new ft[length];
		System.arraycopy(all, 0, res, 0, length);
		Arrays.sort(res);
		for (int i = 0; i < res.length; i++) {
			System.out.println(res[i].name);
		}

	}
}
class ft implements Comparable<ft>{
	String name;
	int tot;
	public ft(String x ,int t) {
		name = x;
		tot = t;
	}
	public int compareTo(ft o) {
		if(tot != o.tot) {
			return o.tot - tot;
		}

		return name.compareTo(o.name);
	}
}

/*
nu
5
g commented on pwyndmh's post
qv posted on g's wall
g likes nu's post
g posted on nu's wall
qv commented on pwyndmh's post
*/


import java.io.PrintWriter;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Vector;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String name = in.nextLine();
        int n = Integer.parseInt(in.nextLine());
        TreeMap<String, Integer> map = new TreeMap<String, Integer>();

        for (int i = 0; i < n; i++) {
            String s = in.nextLine();

            String[] spl1 = s.split("'");
            String[] spl2 = spl1[0].split(" ");

            String[] names = new String[2];
            names[0] = spl2[0];
            names[1] = spl2[spl2.length - 1];

            int add = 0;
            if (names[0].equals(name) || names[1].equals(name)) {
                if (spl2[1].startsWith("p"))
                    add = 15;
                else if (spl2[1].startsWith("c"))
                    add = 10;
                else
                    add = 5;
            }

            for (String str : names)
                if (map.containsKey(str))
                    map.put(str, map.get(str) + add);
                else
                    map.put(str, add);
        }

        while (map.size() > 0) {
            int max = Integer.MIN_VALUE;
            for (String str : map.keySet())
                max = Math.max(max, map.get(str));

            Vector<String> v = new Vector<String>();

            for (String str : map.keySet())
                if (map.get(str) == max)
                    v.add(str);

            Collections.sort(v);

            for (String str : v) {
                if (!str.equals(name))
                    out.println(str);
                map.remove(str);
            }
        }

        out.close();
    }
}


    import java.io.*;
    import java.text.*;
    import java.util.*;
import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            String[] reg = {"([\\w]+)\\sposted\\son\\s([\\w]+)'s\\swall",
                        "([\\w]+)\\scommented\\son\\s([\\w]+)'s\\spost",
                        "([\\w]+)\\slikes\\s([\\w]+)'s\\spost"};

            String n1, n2, s;
            int point, n;
            int[] points = {15, 10, 5};

            void swap(String a, String b) {
                String tmp = a;
                a = b;
                b = tmp;
            }

            void get(String s) {
                /*
                 *      1. человек X написал на стене человек Y ("X posted on Y's wall") — 15 очков;
                        2. человек X прокомментировал сообщение человека Y ("X commented on Y's post") — 10 очков;
                        3. человеку X понравилось сообщение человека Y ("X likes Y's post") — 5 очков.
                 */
                n1 = "";
                n2 = "";
                point = 0;

                for(int i = 0; i < reg.length; ++i) {
                    Pattern p = Pattern.compile(reg[i]);
                    Matcher m = p.matcher(s);

                    if(m.find()) {
                        n1 = m.group(1);
                        n2 = m.group(2);
                        point = points[i];

                        if(n2.equals(s))
                            swap(n1, n2);

                        break;
                    }
                }
            }

            @Override
            public void run() {
                //TODO code
                s = nextToken();
                n = nextInt();
                HashMap<String, Integer> n2i = new HashMap<String, Integer>();
                HashMap<Integer, PriorityQueue<String>> i2n = new HashMap<Integer, PriorityQueue<String>>();

                for(int i = 0; i < n; ++i) {
                    get(nextLine());
                    n2i.put(n1, n2i.containsKey(n1) ? n2i.get(n1) + point : point);
                    n2i.put(n2, n2i.containsKey(n2) ? n2i.get(n2) + point : point);
                }

                Set<String> keys = n2i.keySet();
                for(String key: keys) {
                    int k = n2i.get(key);

                    if(!i2n.containsKey(k))
                        i2n.put(k, new PriorityQueue<String>());

                    i2n.get(k).add(key);
                }

                Object[] dig = i2n.keySet().toArray();
                for(int i = dig.length - 1; i >=0; --i)
                    if(i2n.containsKey(dig[i])) {
                        Object[] r = i2n.get(dig[i]).toArray();
                        for(Object str: r)
                            if(!str.equals(s))
                                print(str.toString() + '\n');
                    }

                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            String[] reg = {"([\\w]+)\\sposted\\son\\s([\\w]+)'s\\swall",
                        "([\\w]+)\\scommented\\son\\s([\\w]+)'s\\spost",
                        "([\\w]+)\\slikes\\s([\\w]+)'s\\spost"};

            String n1, n2, s;
            int point, n;
            int[] points = {15, 10, 5};

            void get(String token) {
                /*
                 *      1. человек X написал на стене человек Y ("X posted on Y's wall") — 15 очков;
                        2. человек X прокомментировал сообщение человека Y ("X commented on Y's post") — 10 очков;
                        3. человеку X понравилось сообщение человека Y ("X likes Y's post") — 5 очков.
                 */

                for(int i = 0; i < reg.length; ++i) {
                    Pattern p = Pattern.compile(reg[i]);
                    Matcher m = p.matcher(token);

                    if(m.find()) {
                        n1 = m.group(1);
                        n2 = m.group(2);

                        if(!n1.equals(s)) {
                            String tmp = n1;
                            n1 = n2;
                            n2 = tmp;
                        }

                        point = n1.equals(s) ? points[i] : 0;
                        break;
                    }
                }
            }

            @Override
            public void run() {
                //TODO code
                s = nextToken();
                n = nextInt();
                HashMap<String, Integer> n2i = new HashMap<String, Integer>();
                HashMap<Integer, PriorityQueue<String>> i2n = new HashMap<Integer, PriorityQueue<String>>();

                for(int i = 0; i < n; ++i) {
                    get(nextLine());
                    n2i.put(n1, n2i.containsKey(n1) ? n2i.get(n1) + point : point);
                    n2i.put(n2, n2i.containsKey(n2) ? n2i.get(n2) + point : point);
                }

                Set<String> keys = n2i.keySet();
                for(String key: keys) {
                    int k = n2i.get(key);

                    if(!i2n.containsKey(k))
                        i2n.put(k, new PriorityQueue<String>());

                    i2n.get(k).add(key);
                }

                Object[] dig = i2n.keySet().toArray();
                Arrays.sort(dig);

                for(int i = dig.length - 1; i >=0; --i)
                    if(i2n.containsKey(dig[i])) {
                        PriorityQueue q = i2n.get(dig[i]);
                        while(q.size() > 0) {
                            String str = q.remove().toString();

                            if(!str.equals(s))
                                print(str.toString() + '\n');
                        }
                    }

                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            String[] reg = {"([\\w]+)\\sposted\\son\\s([\\w]+)'s\\swall",
                        "([\\w]+)\\scommented\\son\\s([\\w]+)'s\\spost",
                        "([\\w]+)\\slikes\\s([\\w]+)'s\\spost"};

            String n1, n2, s;
            int point, n;
            int[] points = {15, 10, 5};

            void get(String token) {
                /*
                 *      1. человек X написал на стене человек Y ("X posted on Y's wall") — 15 очков;
                        2. человек X прокомментировал сообщение человека Y ("X commented on Y's post") — 10 очков;
                        3. человеку X понравилось сообщение человека Y ("X likes Y's post") — 5 очков.
                 */

                for(int i = 0; i < reg.length; ++i) {
                    Pattern p = Pattern.compile(reg[i]);
                    Matcher m = p.matcher(token);

                    if(m.find()) {
                        n1 = m.group(1);
                        n2 = m.group(2);

                        if(!n1.equals(s)) {
                            String tmp = n1;
                            n1 = n2;
                            n2 = tmp;
                        }

                        point = n1.equals(s) ? points[i] : 0;
                        break;
                    }
                }
            }

            @Override
            public void run() {
                //TODO code
                s = nextToken();
                n = nextInt();
                HashMap<String, Integer> n2i = new HashMap<String, Integer>();
                HashMap<Integer, PriorityQueue<String>> i2n = new HashMap<Integer, PriorityQueue<String>>();

                for(int i = 0; i < n; ++i) {
                    get(nextLine());
                    n2i.put(n1, n2i.containsKey(n1) ? n2i.get(n1) + point : point);
                    n2i.put(n2, n2i.containsKey(n2) ? n2i.get(n2) + point : point);
                }

                Set<String> keys = n2i.keySet();
                for(String key: keys) {
                    int k = n2i.get(key);

                    if(!i2n.containsKey(k))
                        i2n.put(k, new PriorityQueue<String>());

                    i2n.get(k).add(key);
                }

                Object[] dig = i2n.keySet().toArray();
                for(int i = dig.length - 1; i >=0; --i)
                    if(i2n.containsKey(dig[i])) {
                        PriorityQueue q = i2n.get(dig[i]);
                        while(q.size() > 0) {
                            String str = q.remove().toString();

                            if(!str.equals(s))
                                print(str.toString() + '\n');
                        }
                    }

                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.util.regex.*;

    public class Main{
        static class Run implements Runnable{
            //TODO parameters
            final boolean consoleIO = true;
            final String inFile = "input.txt";
            final String outFile = "output.txt";

            String[] reg = {"([\\w]+)\\sposted\\son\\s([\\w]+)'s\\swall",
                        "([\\w]+)\\scommented\\son\\s([\\w]+)'s\\spost",
                        "([\\w]+)\\slikes\\s([\\w]+)'s\\spost"};

            String n1, n2, s;
            int point, n;
            int[] points = {15, 10, 5};

            void get(String token) {
                /*
                 *      1. человек X написал на стене человек Y ("X posted on Y's wall") — 15 очков;
                        2. человек X прокомментировал сообщение человека Y ("X commented on Y's post") — 10 очков;
                        3. человеку X понравилось сообщение человека Y ("X likes Y's post") — 5 очков.
                 */

                for(int i = 0; i < reg.length; ++i) {
                    Pattern p = Pattern.compile(reg[i]);
                    Matcher m = p.matcher(token);

                    if(m.find()) {
                        n1 = m.group(1);
                        n2 = m.group(2);

                        if(!n1.equals(s)) {
                            String tmp = n1;
                            n1 = n2;
                            n2 = tmp;
                        }

                        point = n1.equals(s) ? points[i] : 0;
                        break;
                    }
                }
            }

            @Override
            public void run() {
                //TODO code
                s = nextToken();
                n = nextInt();
                HashMap<String, Integer> n2i = new HashMap<String, Integer>();
                HashMap<Integer, PriorityQueue<String>> i2n = new HashMap<Integer, PriorityQueue<String>>();

                for(int i = 0; i < n; ++i) {
                    get(nextLine());
                    n2i.put(n1, n2i.containsKey(n1) ? n2i.get(n1) + point : point);
                    n2i.put(n2, n2i.containsKey(n2) ? n2i.get(n2) + point : point);
                }

                Set<String> keys = n2i.keySet();
                for(String key: keys) {
                    int k = n2i.get(key);

                    if(!i2n.containsKey(k))
                        i2n.put(k, new PriorityQueue<String>());

                    i2n.get(k).add(key);
                }

                Object[] dig = i2n.keySet().toArray();
                for(int i = dig.length - 1; i >=0; --i)
                    if(i2n.containsKey(dig[i])) {
                        Object[] r = i2n.get(dig[i]).toArray();
                        for(Object str: r)
                            if(!str.equals(s))
                                print(str.toString() + '\n');
                    }

                close();
            }
        //=========================================================================================================================
            BufferedReader in;
            PrintWriter out;
            StringTokenizer strTok;

            Run() {
                if (consoleIO) {
                    initConsoleIO();
                }
                else {
                    initFileIO();
                }
            }

            void initConsoleIO() {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }

            void initFileIO() {
                try {
                    in = new BufferedReader(new FileReader(inFile));
                    out = new PrintWriter(new FileWriter(outFile));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            void close() {
                try {
                    in.close();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            int nextInt() {
                return Integer.parseInt(nextToken());
            }

            double nextDouble() {
                return Double.parseDouble(nextToken());
            }

            float nextFloat() {
                return Float.parseFloat(nextToken());
            }

            long nextLong() {
                return Long.parseLong(nextToken());
            }

            String nextLine() {
                try {
                    return in.readLine();
                } catch (IOException e) {
                    return "__NULL";
                }
            }

            boolean hasMoreTokens() {
                return (strTok == null) || (strTok.hasMoreTokens());
            }

            String nextToken() {
                while (strTok == null || !strTok.hasMoreTokens()) {
                    String line;
                    try {
                        line = in.readLine();
                        strTok = new StringTokenizer(line);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                return strTok.nextToken();
            }

            void cout(Object o){
                System.out.println(o);
            }

            void print(Object o) {
                out.write(o.toString());
            }

            void printf(String format, Object... args) {
                out.printf(format, args);
            }

            String sprintf(String format, Object... args) {
            return MessageFormat.format(format, args);
        }
        }

        static class Pair<A, B> {
            A a;
            B b;

            A f() {
                return a;
            }

            B s() {
                return b;
            }

            Pair(A a, B b) {
                this.a = a;
                this.b = b;
            }

            Pair(Pair<A, B> p) {
                a = p.f();
                b = p.s();
            }
        }

        public static void main(String[] args) throws IOException {
            Run run = new Run();
            Thread thread = new Thread(run);
            thread.run();
        }
    }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Author -
 * User: kansal
 * Date: 4/13/11
 * Time: 8:41 PM
 */
public class TaskB {
    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        Map<String, Integer> P = new HashMap<String, Integer>();
        P.put("posted", 15);
        P.put("commented", 10);
        P.put("likes", 5);

        String me = next();
        int n = nextInt();
        final Map<String, Integer> dic = new TreeMap<String, Integer>();
        for(int i = 0; i < n; ++i) {
            String line = nextLine();
            String[] parts = line.split(" ");

            String a = parts[0];
            String b = parts[parts.length - 2];
            b = b.substring(0, b.length() - 2);

            String action = parts[1];
            int points = P.get(action);

            if (!a.equals(me) && !b.equals(me)) {
                points = 0;
            }

            if (!a.equals(me)) {
                if (!dic.containsKey(a)) {
                    dic.put(a, 0);
                }
                dic.put(a, dic.get(a) + points);
            }
            if (!b.equals(me)) {
                if (!dic.containsKey(b)) {
                    dic.put(b, 0);
                }
                dic.put(b, dic.get(b) + points);
            }
        }

        List<String> names = new ArrayList<String>();
        for(String s: dic.keySet()) {
            names.add(s);
        }

        Collections.sort(names, new Comparator<String>() {
            public int compare(String o1, String o2) {
                if (dic.get(o1) != dic.get(o2)) {
                    return -(dic.get(o1) - dic.get(o2));
                }
                return o1.compareTo(o2);
            }
        });

        for(String s: names) {
            System.out.println(s);
        }
    }

    public static BufferedReader reader;

    public static StringTokenizer tokenizer = null;

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static public String next() {
        return nextToken();
    }

    static public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * Author -
 * User: kansal
 * Date: 4/13/11
 * Time: 8:41 PM
 */
public class TaskB {
    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        Map<String, Integer> P = new HashMap<String, Integer>();
        P.put("posted", 15);
        P.put("commented", 10);
        P.put("likes", 5);

        String me = next();
        int n = nextInt();
        Map<String, Integer> dic = new TreeMap<String, Integer>();
        for(int i = 0; i < n; ++i) {
            String line = nextLine();
            String[] parts = line.split(" ");

            String a = parts[0];
            String b = parts[parts.length - 2];
            b = b.substring(0, b.length() - 2);

            String action = parts[1];
            int points = P.get(action);

            if (!a.equals(me) && !b.equals(me)) {
                points = 0;
            }

            if (!a.equals(me)) {
                if (!dic.containsKey(a)) {
                    dic.put(a, 0);
                }
                dic.put(a, dic.get(a) + points);
            }
            if (!b.equals(me)) {
                if (!dic.containsKey(b)) {
                    dic.put(b, 0);
                }
                dic.put(b, dic.get(b) + points);
            }
        }
        Set<String> names = dic.keySet();
        for(String name: names) System.out.println(name);
    }

    public static BufferedReader reader;

    public static StringTokenizer tokenizer = null;

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static public String next() {
        return nextToken();
    }

    static public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    try {
                        if (new File("input.txt").exists())
                            System.setIn(new FileInputStream("input.txt"));
                    } catch (SecurityException e) {}
                    new Main().run();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1L << 24).start();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    String me;
    Map<String, Integer> map = new HashMap<String, Integer>(100);

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        me = nextToken();

        for (int Q = nextInt(); Q --> 0; ) {
            String name1 = nextToken();
            String action  = nextToken();
            if (!action.equals("likes"))
                nextToken();
            String name2 = nextToken();
            name2 = name2.substring(0, name2.length() - 2);
            if (me.equals(name1))
                add(name2, score(action));
            if (me.equals(name2))
                add(name1, score(action));
            nextToken();
        }

        Item[] friends = new Item [map.size()];
        int k = 0;
        for (Map.Entry<String, Integer> e : map.entrySet())
            friends[k++] = new Item(e.getKey(), e.getValue());
        sort(friends);
        for (Item item : friends)
            out.println(item.name);

        out.close();
    }

    void add(String who, int score) {
        if (!map.containsKey(who))
            map.put(who, 0);
        map.put(who, map.get(who) + score);
    }

    int score(String act) {
        if (act.equals("posted"))
            return 15;
        if (act.equals("commented"))
            return 10;
        if (act.equals("likes"))
            return 5;
        throw new RuntimeException("Bad string!!!");
    }

    class Item implements Comparable<Item> {
        String name;
        int score;

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

        @Override
        public int compareTo(Item item) {
            if (score != item.score)
                return score > item.score ? -1 : 1;
            return name.compareTo(item.name);
        }
    }

    /***************************************************************
     * Input
     **************************************************************/
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
    public static void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    try {
                        if (new File("input.txt").exists())
                            System.setIn(new FileInputStream("input.txt"));
                    } catch (SecurityException e) {}
                    new Main().run();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1L << 24).start();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    String me;
    Map<String, Integer> map = new HashMap<String, Integer>(100);

    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        me = nextToken();

        for (int Q = nextInt(); Q --> 0; ) {
            String name1 = nextToken();
            String action  = nextToken();
            if (!action.equals("likes"))
                nextToken();
            String name2 = nextToken();
            name2 = name2.substring(0, name2.length() - 2);
            if (me.equals(name1))
                add(name2, score(action));
            else
                add(name1, 0);
            if (me.equals(name2))
                add(name1, score(action));
            else
                add(name2, 0);
            nextToken();
        }

        Item[] friends = new Item [map.size()];
        int k = 0;
        for (Map.Entry<String, Integer> e : map.entrySet())
            friends[k++] = new Item(e.getKey(), e.getValue());
        sort(friends);
        for (Item item : friends)
            out.println(item.name);

        out.close();
    }

    void add(String who, int score) {
        if (!map.containsKey(who))
            map.put(who, 0);
        map.put(who, map.get(who) + score);
    }

    int score(String act) {
        if (act.equals("posted"))
            return 15;
        if (act.equals("commented"))
            return 10;
        if (act.equals("likes"))
            return 5;
        throw new RuntimeException("Bad string!!!");
    }

    class Item implements Comparable<Item> {
        String name;
        int score;

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

        @Override
        public int compareTo(Item item) {
            if (score != item.score)
                return score > item.score ? -1 : 1;
            return name.compareTo(item.name);
        }
    }

    /***************************************************************
     * Input
     **************************************************************/
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class SRM67_2 {
    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String myname = in.readLine();
        int actions = Integer.parseInt(in.readLine());
        int m = 0;
        HashMap<String,Integer> map = new HashMap<String,Integer>();
        aa [] out = new aa[1000];
        for (int i = 0; i < actions; i++) {
            String [] a = in.readLine().split(" ");
            String name1 = a[0];
            String name2 = a[a.length-2].substring(0,a[a.length-2].length()-2);
            String act = a[1];
            int bonus = 0;
            if(act.equals("posted"))
                bonus = 15;
            else if(act.equals("commented"))
                bonus = 10;
            else
                bonus = 5;
            int hash = 0;
            if(name1.equals(myname)){
                if(!map.containsKey(name2)){
                map.put(name2,m);
                hash = m;
                m++;
                out[hash] = new aa(name2,bonus);
                }else{
                    hash = map.get(name2);
                    out[hash].a+=bonus;
                }
            }else if(name2.equals(myname)){
                if(!map.containsKey(name1)){
                map.put(name1,m);
                hash = m;
                m++;
                out[hash] = new aa(name1,bonus);
                }else{
                    hash = map.get(name1);
                    out[hash].a+=bonus;
                }
            }else{
                if(!map.containsKey(name1)){
                    map.put(name1,m);
                    hash = m;
                    m++;
                    out[hash] = new aa(name1,0);
                }
                if(!map.containsKey(name2)){
                    map.put(name2,m);
                    hash = m;
                    m++;
                    out[hash] = new aa(name2,0);
                }
            }
        }
        aa[] temp = new aa[map.size()];
        int k = 0;
        for (int i = 0; i < out.length; i++) {
            if(out[i]!=null){
                temp[k++] = out[i];
            }
        }
        Arrays.sort(temp);
        for (int i = 0; i < temp.length; i++) {
            System.out.println(temp[i].b);
        }
    }
}
class aa implements Comparable<aa>{
    String b;
    int a;
    public aa(String k , int aa){
        b = k;
        a = aa;
    }
    public int compareTo(aa o) {
        if(a>o.a)
            return -1;
        else if(a<o.a)
            return 1;
        else
            return b.compareTo(o.b);
    }
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import static java.lang.Math.*;

public class BetaRound67_B implements Runnable {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws IOException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken(" '");
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    @Override
    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    public static void main(String[] args) {
        new Thread(new BetaRound67_B()).start();
    }

    int score(String s) {
        if (s.equals("posted")) return 15;
        if (s.equals("commented")) return 10;
        if (s.equals("likes")) return 5;
        throw new RuntimeException();
    }

    Map<String, Integer> map = new HashMap<String, Integer>();

    void inc(String name, int score) {
        if (map.containsKey(name)) {
            map.put(name, map.get(name) + score);
        } else {
            map.put(name, score);
        }
    }

    void solve() throws IOException {
        String my = readString();
        int n = readInt();

        while (n --> 0) {
            String name1 = readString();
            String type = readString();
            int score = score(type);
            if (!type.equals("likes")) readString();
            String name2 = readString();
            readString();
            readString();
            if (!name1.equals(my) && !name2.equals(my)) {
                inc(name1, 0);
                inc(name2, 0);
                continue;
            }
            if (name1.equals(my)) {
                inc(name2, score);
                continue;
            }
            if (name2.equals(my)) {
                inc(name1, score);
                continue;
            }
            throw new RuntimeException();
        }
        List<Entry<String, Integer>> a = new ArrayList<Entry<String,Integer>>(map.entrySet());
        Collections.sort(a, new Comparator<Entry<String, Integer>>() {
            @Override
            public int compare(Entry<String, Integer> o1,
                    Entry<String, Integer> o2) {
                if (o1.getValue() > o2.getValue()) return -1;
                if (o1.getValue() < o2.getValue()) return 1;
                return o1.getKey().compareTo(o2.getKey());
            }
        });
        for (Entry<String, Integer> e : a) {
            out.println(e.getKey());
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        inB = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(inB);
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args)throws Exception {
        String myName = inB.readLine();
        int n = Integer.parseInt(inB.readLine());

        HashMap<String, friend> hm = new HashMap<String, friend>();
        ArrayList<friend> al = new ArrayList<friend>();

        int curi = 0;
        for(int i = 0; i<n; i++) {
            String s = inB.readLine();

            String[] ss = s.split(" ");
            String fir = ss[0];
            String sec = ss[ss.length - 2].split("'")[0];

            if(!hm.containsKey(fir) && !fir.equals(myName)) {
                friend f = new friend(fir);
                hm.put(fir, f);
                al.add(f);
            }

            if(!hm.containsKey(sec) && !sec.equals(myName)) {
                friend f = new friend(sec);
                hm.put(sec, f);
                al.add(f);
            }

            if(!fir.equals(myName) && !sec.equals(myName))continue;

            friend f1 = fir.equals(myName) ? null : hm.get(fir), f2 = sec.equals(myName) ? null : hm.get(sec);

            String com = ss[1];

            int change = (com.equals("likes")) ? 5 : com.equals("commented") ? 10 : 15;

            if(!fir.equals(myName)) {
                f1.coef += change;
            } else {
                f2.coef += change;
            }
        }

        friend[] fr = new friend[al.size()];

        for(int i = 0; i<al.size(); i++) {
            fr[i] = (al.get(i));
        }

        Arrays.sort(fr);

        for(int i = fr.length - 1; i>=0; i--) {
            out.println(fr[i].name);
        }
        out.flush();
    }
}

class friend implements Comparable<friend> {
    String name;
    int coef;

    public friend(String name) {
        this.name = name;
        this.coef = 0;
    }

    @Override
    public int compareTo(friend f) {
        // TODO Auto-generated method stub
        if(coef == f.coef) {
            return -name.compareTo(f.name);
        }
        return new Integer(coef).compareTo(f.coef);
    }
}


import java.util.*;
import java.text.*;
import java.io.*;

public class Cf75B implements Runnable {
     Map< String, Integer > posts = new HashMap< String, Integer >( );
     class Message {
         String m;
         int c;

         Message( String a, int b ) {
             m = a;
             c = b;
         }

         public String toString( ) {
             return  m + " " + c;
         }

     }
     public void solve( ) throws Throwable {
          String me = nextLine( );
          int numPosts = nextInt( );
          while ( numPosts --> 0 ) {
              String s = nextLine( );
              String sp[ ] = s.split( " " );
              String first = null, second = null;
              int toAdd = 0;
              if ( sp.length == 5 ) {
                  first = sp[ 0 ];
                  second = sp[ 3 ].substring( 0, sp[ 3 ].indexOf( "'" ) );
                  /*String t = "";

                  for ( int i = 0; i < second.length( ); ++i ) {
                      if ( second.charAt( i ) == '\'' ) {
                          break;
                      }
                      t += second.charAt( i );

                  }
                  second = t; */
                  if ( sp[ 1 ].equals( "posted" ) ) {
                      toAdd = 15;
                  } else {

                      toAdd = 10;
                  }
              } else {
                  first = sp[ 0 ];

                  second = sp[ 2 ].substring( 0, sp[ 2 ].indexOf( "'" ) );

                      /*second = sp[ 2 ];
                  String t = "";

                  for ( int i = 0; i < second.length( ); ++i ) {
                      if ( second.charAt( i ) == '\'' ) {
                          break;
                      }
                      t += second.charAt( i );

                  }
                  second = t;
                  */
                  toAdd = 5;
              }
              if ( second.equals( me ) ) {
                  Integer a = posts.get( first );
                  if  ( a == null ) {
                      a = 0;
                  }
                  posts.put( first, a + toAdd );
              }else if ( first.equals( me ) ) {
                  Integer b = posts.get( second );
                  if ( b == null ) {
                      b = 0;
                  }
                  posts.put( second, b + toAdd );
              } else {
                  posts.put( first, 0 );
                  posts.put( second, 0 );
              }

          }

         List< Message > list = new ArrayList< Message >( );
         for (  Map.Entry< String, Integer > e : posts.entrySet( ) ) {
             list.add( new Message( e.getKey( ), e.getValue( ) ) );
         }
         //out.println( list );
         Collections.sort( list, new Comparator< Message >( ) {
                  public int compare( Message a, Message b ) {
                      if ( a.c != b.c ) {
                          return a.c > b.c ? -1 : 1;
                      }
                      return a.m.compareTo( b.m );
                  }
             } );
         for ( Message m : list ) {
             out.println( m.m );
         }

     }

     public void run( ) {
         try {
             solve( );
             out.close( );
         } catch( Throwable e ) {
             e.printStackTrace( );
         }
     }

     public static void main( String[ ] args ) {
         new Thread( new Cf75B( ) ).start( );
     }

     BufferedReader bIn = new BufferedReader( new InputStreamReader( System.in ) );
     PrintWriter out = new PrintWriter( new PrintStream( System.out ), true );
     StringTokenizer st = new StringTokenizer( "" );

     private void split( String s ) {
         st = new StringTokenizer( s );
     }

     private int nextInt( ) throws Throwable {
         return Integer.parseInt( next( ) );
     }

     private double nextDouble( ) throws Throwable {
         return Double.parseDouble( next( ) );
     }

     private long nextLong( ) throws Throwable {
         return Long.parseLong( next( ) );
     }

     private String next( ) throws Throwable {
         while ( !st.hasMoreTokens( ) ) {
             String l = bIn.readLine( );
             if ( l == null ) {
                 return null;
             }
             split( l );

         }

         return st.nextToken( );
     }

     private String nextLine( ) throws Throwable {
         st = new StringTokenizer( "" );
         return bIn.readLine( );
     }

     private boolean isEOF( ) throws Throwable {
         while ( !st.hasMoreTokens( ) ) {
              String s = bIn.readLine( );
              if ( s == null ) return true;
              split( s );
         }

         return false;
     }

}