// Arup Guha
// 7/20/2015
// Solution to 2010 UCF Fall Locals Problem: Texting (g2g c u 18r)

import java.util.*;

public class texting {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int mapSize = Integer.parseInt(stdin.nextLine().trim());

		// Create our text dictionary.
		HashMap<String,String> dictionary = new HashMap<String,String>();
		for (int i=0; i<mapSize; i++) {
			String line = stdin.nextLine();
			int split = line.indexOf(' ');
			dictionary.put(line.substring(0, split), line.substring(split+1));
		}

		// Process sentences.
		int numCases = Integer.parseInt(stdin.nextLine().trim());
		for (int loop=0; loop<numCases; loop++) {

			// Tokenize this sentence.
			StringTokenizer tok = new StringTokenizer(stdin.nextLine());
			while (tok.hasMoreTokens()) {
				String word = tok.nextToken();
				if (dictionary.containsKey(word))
					System.out.print(dictionary.get(word));
				else
					System.out.print(word);
				if (tok.hasMoreTokens()) System.out.print(" ");
			}

			// Go to next line.
			System.out.println();
		}
	}
}