// Arup Guha
// 4/1/2026
// Solution to COP 3330 Program 7B: Radio Version

import java.util.*;

public class Radio {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		StringTokenizer tok = new StringTokenizer(stdin.nextLine());
		
		// Get number of banned words and number of songs to translate.
		int numWords = Integer.parseInt(tok.nextToken());
		int numSongs = Integer.parseInt(tok.nextToken());
		
		// We'll put safe words here.
		HashMap<String,String> safeWords = new HashMap<String,String>();
		
		// Add each mapping here.
		for (int i=0; i<numWords; i++) {
			tok = new StringTokenizer(stdin.nextLine());
			String bad = tok.nextToken();
			String good = tok.nextToken();
			safeWords.put(bad, good);
		}
		
		// Process each song.
		for (int i=0; i<numSongs; i++) {
			tok = new StringTokenizer(stdin.nextLine());
			
			// Go through each word.
			while (tok.countTokens() > 0) {
			
				String tmp = tok.nextToken();
				
				// Update word if necessary.
				if (safeWords.containsKey(tmp))
					tmp = safeWords.get(tmp);
					
				// Put a space after each word. (Okay to not put a space after the last word.)
				System.out.print(tmp+" ");
			}
			
			// Go to the next song.
			System.out.println();
		}
	}
}