// Задача "Программа ..."
// Восьмая Всероссийская олимпиада школьников по программирвоани.
// Автор решения: Федор Царев, tsarev@rain.ifmo.ru

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

public class program_ft implements Runnable {

	public final static double MAX_N = 50;
	public final static double MAX_KEYWORD_LENGTH = 50;
	public final static double MAX_FILESIZE = 10 * 1024;

	private Scanner in;
	private PrintWriter out;
	String fname = "program";

	private void myAssert(boolean e, String message) {
		if (!e) {
			throw new Error("Assertion failure!!! " + message);
		}
	}

	boolean isKeyword(String s) {
		int n = s.length();
		if (n > MAX_KEYWORD_LENGTH) {
			return false;
		}
		for (int i = 0; i < n; i++) {
			char ch = s.charAt(i);
			if (ch == '_') {
		    	continue;
			}
			if ('a' <= ch && ch <= 'z') {
				continue;
			}
			if ('A' <= ch && ch <= 'Z') {
				continue;
			}
			return false;
		}
		return true;
	}

	boolean isCharacter(char ch) {
		return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9') || (ch == '_');
	}

	boolean isWhitespace(char ch) {
		return !isCharacter(ch);
	}

	boolean canBeId(String s, boolean digitCanBeFirst) {
		int n = s.length();
		char first = s.charAt(0);
		boolean haveNotDigit = false;
		for (int i = 0; i < n; i++) {
			char ch = s.charAt(i);
			haveNotDigit |= !('0' <= ch && ch <= '9');
		}
		boolean firstIsGood = false;
		if (digitCanBeFirst) {
			firstIsGood = true;
		} else {
			if ('0' <= first && first <= '9') {
				firstIsGood = false;
			} else {
				firstIsGood = true;
			}			
		}
		return haveNotDigit && firstIsGood;
	}

	public void solve() {
		int n = in.nextInt();
		String c = in.next();
		String d = in.next();
		myAssert(0 <= n && n <= MAX_N, "n is out of bounds");
		myAssert("no".equals(c) || "yes".equals(c), "Word c is neither 'yes' nor 'no'");
		myAssert("no".equals(d) || "yes".equals(d), "Word d is neither 'yes' nor 'no'");
		HashSet<String> keywords = new HashSet<String>();
		HashMap<String, Integer> keywordsLowerCase = new HashMap<String, Integer>();
		for (int i = 0; i < n; i++) {
			String s = in.next();                                
			myAssert(isKeyword(s), "s = '" + s +"' is not a keyword");
			keywords.add(s);
			String t = s.toLowerCase();								
			if (keywordsLowerCase.get(t) != null) {
				myAssert(false, "Keywords #" + i + " and #" + keywordsLowerCase.get(t) + " are same case insensitive");			
			}
			keywordsLowerCase.put(t, i);
		}
		in.nextLine();
		                                        
		ArrayList<String> idList = new ArrayList<String>();
		HashMap<String, Integer> occurencies = new HashMap<String, Integer>();

		StringBuilder sb = new StringBuilder();
		while (in.hasNext()) {
			sb.append(in.next());
			sb.append(" ");
		}
		String s = sb.toString();
		int l = s.length();
		int p = 0;
		while (p < l) {
			StringBuilder curId = new StringBuilder();
			while (p < l && isWhitespace(s.charAt(p))) {
				p++;
			}
			while (p < l && isCharacter(s.charAt(p))) {
				curId.append(s.charAt(p));
				p++;
			} 	
			if (curId.length() == 0) {
				continue;
			}
			String id = curId.toString();
			String idLowerCase = id.toLowerCase();
			if (!canBeId(id, "yes".equals(d))) {
				continue;
			}
			String toAdd = null;
			if ("yes".equals(c)) {
				if (keywords.contains(id)) {
					continue;
				}
				toAdd = id;
			} else {        
				if (keywordsLowerCase.containsKey(idLowerCase)) {
					continue;
				}
				toAdd = idLowerCase;
			}
			if (occurencies.get(toAdd) == null) {
				occurencies.put(toAdd, 1);
				idList.add(toAdd);
			} else {
				occurencies.put(toAdd, occurencies.get(toAdd) + 1);
			}
		}
		int max = -1;    
		String ans = null;
		for (String id : idList) {
			int curOc = occurencies.get(id);
			if (curOc > max) {
				max = curOc;
				ans = id;
			}
		}
		myAssert(ans != null, "ans is null");
		out.println(ans);
	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}		
	}

	public program_ft() {
		try {
			in = new Scanner(new File(fname + ".in"));
			int size = 0;
			BufferedReader br = new BufferedReader(new FileReader(fname + ".in"));
			int lineNum = 0;
			while (true) {
				String s = br.readLine();
				if (s == null) {
					break;
				}
				lineNum++;
				int pos = 0;
				for (char ch : s.toCharArray()) {
					pos++;
					assert 32 <= ch && ch <= 126 : "Invalid sumbol at line " + lineNum + ", position " + pos + " code = " + ((int) ch);
				}
				size += s.length() + 2;
			}
			myAssert(size <= MAX_FILESIZE, "File is too big");
			out = new PrintWriter(new File(fname + ".out"));
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}


	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new Thread(new program_ft()).start();
	}

}                       