public static void main(String args[]) throws Exception
	{
		WordFreq solution = new WordFreq();
		solution.table = new Hashtable<String, Integer>();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		//System.out.println("Input the number of terms to add.");
		solution.n = Integer.parseInt(in.readLine());
		
		//System.out.println("Input your terms.");
		for (int i = 0; i < solution.n; i++)
		{
			String term = in.readLine();
			if (!solution.table.containsKey(term))
				solution.table.put(term, 1);
			else
				solution.table.put(term, solution.table.get(term) + 1);
		}
		
		Enumeration<String> termEnum = solution.table.keys();
		Enumeration<Integer> freqEnum = solution.table.elements();
		
		solution.termArray = new String[solution.table.size()];
		solution.freqArray = new int[solution.table.size()];
		
		int i = 0;
		while (termEnum.hasMoreElements() && freqEnum.hasMoreElements())
		{
			solution.termArray[i] = termEnum.nextElement();
			solution.freqArray[i] = freqEnum.nextElement();
			i++;
		}
		
		quicksort(solution.termArray, solution.freqArray, 0, solution.table.size() - 1);
		//System.out.println("Input how many terms to print");
		solution.k = Integer.parseInt(in.readLine());
		
		for (i = solution.termArray.length - 1; i > solution.termArray.length - solution.k - 1; i--)
			System.out.println(solution.termArray[i]);
	}