/* Задача "Финал ACM ICPC"
 * Интернет олимпиады для школьников. Сезон 2006 - 2007
 * Автор задачи:  Александр Торопов, toropov@rain.ifmo.ru
 * Автор решения: Александр Торопов, toropov@rain.ifmo.ru
 */

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

public class final_at_sort implements Runnable {
	BufferedReader in;
	PrintWriter out;
	
	class Team {
		String team;
		int number;
		int place;
	}
	
	public void solve() throws IOException {
		StringTokenizer st = new StringTokenizer(in.readLine());
		int p = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		ArrayList<Team> array = new ArrayList<Team>(); 
		Team teams[] = new Team[p];
		for(int i = 0; i < p; ++i) {
			teams[i] = new Team();
			teams[i].team = in.readLine();
			teams[i].place = i;
		}
		st = new StringTokenizer(in.readLine());
		for(int i = 0; i < p; ++i) {
			teams[i].number = Integer.parseInt(st.nextToken());
		}
		Arrays.sort(teams, new Comparator<Team>() {
			public int compare(Team a, Team b) {
				if (a.team.compareTo(b.team) != 0)
					return a.team.compareTo(b.team);
				if (a.place < b.place) 
					return -1;
				if (a.place > b.place)
					return 1;
				return 0;
			}
		});
		String cur = teams[0].team;
		int len = 1;
		array.add(teams[0]);
		for(int i = 1; i < teams.length; ++i) {
			if (cur.equals(teams[i].team)) {
				++len;
				if (len <= k) {
					array.add(teams[i]);
				}
			}
			else {
				array.add(teams[i]);
				cur = teams[i].team;
				len = 1;
			}
		}
		Team print[] = new Team[array.size()];
		for(int i = 0; i < print.length; ++i) {
			print[i] = array.get(i);
		}
		Arrays.sort(print, new Comparator<Team>(){
			public int compare(Team a, Team b) {
				if (a.place < b.place)
					return -1;
				if (a.place > b.place)
					return 1;
				return 0;
			}
		});
		for(int i = 0; i < Math.min(array.size(), n); ++i) {
			out.println(print[i].team + " #" + print[i].number);
		}
	}
	
	public void run() {
		try {
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(89);
		} finally {
			out.close();
		}
	}
	
	private final_at_sort(String name) {
		try {
			in = new BufferedReader(new FileReader(name + ".in"));
			out = new PrintWriter(new File(name + ".out"));
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(89);
		}
	}

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