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

public class program_al {
  static final int MaxN = 50, MaxL = 50, MaxSize = 100000;

  static void error (String s) throws Exception {
    throw new RuntimeException (s);
  };

  static Scanner in; 

  static int rangeInt (int a, int b) throws Exception {
    int x = in.nextInt ();
    if (x < a && x > b) error ("Integer " + x + " is not in range " + a + ".." + b);
    return x;
  };


  static boolean getBool () throws Exception {
    String s = in.next ();
    if (s.equals ("yes")) return true;
    if (s.equals ("no")) return false;
    error ("'yes' or 'no' expected instead of " + s);
    return false;
  };

  static String s;
  static int p, pos;
  static boolean completed;

  static char nc () {
    if (p >= s.length ()) {
      if (!in.hasNextLine ()) {
        completed = true;
        return (char)26;
      };
      s = in.nextLine ();
      p = 0;
      return (char)13;
    };
    char c = s.charAt (p);
    ++p;
    ++pos;
    return c;
  };


  public static void main (String args []) throws Exception {
    in = new Scanner (new File ("program.in"));
    PrintWriter out = new PrintWriter ("program.out");
    int n = rangeInt (0, MaxN);
    boolean sens = getBool ();
    boolean dig = getBool ();

    Set <String> res = new HashSet <String> ();

    for (int i = 0; i < n; i++) {
      String t = in.next ();
      if (t.length () == 0 || t.length () > MaxL)
        error ("Reserved word length not in range 1.." + MaxL + ": " + t.length ());
      for (int j = 0; j < t.length (); j++)
        if (!
             (
              (t.charAt (j) >= 'A' && t.charAt (j) <= 'Z') ||
              (t.charAt (j) >= 'a' && t.charAt (j) <= 'z') ||
              t.charAt (j) == '_'
             )                                           
           ) error ("Invalid character in reserved word: " + t.charAt (j));
      if (!sens) t = t.toLowerCase ();
      if (res.contains (t)) error ("Repeated reserved word " + t);
      res.add (t);
    };

    s = in.nextLine ();
    p = 0;
    pos = 0;
    completed = false;
    int state = 0;

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

    char z [] = new char[MaxSize]; 
    int cp = 0;

    int mx = 0, mp = 0;
    String ms = "";

    boolean notdig = false;

    while (!completed) {
      char t = nc ();
      switch (state) {
        case 0:
          if ( 
              (t >= 'A' && t <= 'Z') ||
              (t >= 'a' && t <= 'z') ||
              (t == '_') ||
              (t >= '0' && t <= '9')
             ) {
            cp = 1;
            z[0] = t;
            state = 1;
            if (t > '9') notdig = true;
          };
          break;
        case 1:
          if ( 
              (t >= 'A' && t <= 'Z') ||
              (t >= 'a' && t <= 'z') ||
              (t == '_') ||
              (t >= '0' && t <= '9')
             ) {
            if (t > '9') notdig = true;
            z[cp] = t;
            ++cp;
          } else {
            String s = new String (z, 0, cp);
            if (!sens) s = s.toLowerCase ();
            if (notdig && (dig || s.charAt (0) > '9')) {
              if (!res.contains (s)) {
                Integer val = ids.get (s);
                int nval;
                if (val == null) {
                  nval = 1;
                  pss.put (s, pos);
                } else
                  nval = val + 1;
                ids.put (s, nval);
                if (nval > mx || (nval == mx && pss.get (s) < mp)) {
                  mx = nval;
                  ms = s;
                  mp = pss.get (s);
                };
              };
            };
            state = 0;
            notdig = false;
          };
          break;
      };
    };

    if (mx == 0) error ("At least one identifier should be present");

    out.println (ms);

    out.close ();
  };
};
