You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.

You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.

You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.

You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.


-----Input-----

The first line contains two integers, n and m (1 ≤ n ≤ 3000, 1 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages.

The following m lines contain the words. The i-th line contains two strings a_{i}, b_{i} meaning that the word a_{i} belongs to the first language, the word b_{i} belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.

The next line contains n space-separated strings c_1, c_2, ..., c_{n} — the text of the lecture. It is guaranteed that each of the strings c_{i} belongs to the set of strings {a_1, a_2, ... a_{m}}.

All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.


-----Output-----

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.


-----Examples-----
Input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest

Output
codeforces round letter round

Input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll

Output
hbnyiyc joll joll un joll

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation


Solutions:
def main():
	(n, m) = map(int, input().split())
	trans = {}
	for _ in range(m):
		temp = list(input().split())
		(a, b) = (temp[0], temp[1])
		if len(a) <= len(b):
			trans[a] = a
		else:
			trans[a] = b
	lecture = list(input().split())
	notes = ''
	for x in lecture:
		notes += trans[x] + ' '
	print(notes)
main()


import sys, math, collections
from collections import defaultdict

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def get_2_ints():
	(a, b) = map(int, input().split())
	return (a, b)

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def floorSqrt(x):
	if x == 0 or x == 1:
		return x
	start = 1
	end = x
	while start <= end:
		mid = (start + end) // 2
		if mid * mid == x:
			return mid
		if mid * mid < x:
			start = mid + 1
			ans = mid
		else:
			end = mid - 1
	return ans

def main():
	(n, m) = get_2_ints()
	d = {}
	for i in range(m):
		(a, b) = input().split()
		d[a] = b
	ans = []
	s = list(input().split())
	for i in s:
		if len(i) < len(d[i]):
			ans.append(i)
		elif len(i) > len(d[i]):
			ans.append(d[i])
		else:
			ans.append(i)
	print(' '.join(ans))
main()


def answer(n, m, a, b, c):
	new_ary = []
	for i in range(len(c)):
		indx = a.index(c[i])
		if len(a[indx]) <= len(b[indx]):
			new_ary.append(a[indx])
		else:
			new_ary.append(b[indx])
	return ' '.join(new_ary)

def main():
	(n, m) = [int(i) for i in input().split()]
	a = ['x'] * m
	b = ['x'] * m
	for j in range(m):
		(a[j], b[j]) = [i for i in input().split()]
	c = [i for i in input().split()]
	print(answer(n, m, a, b, c))
main()


(n, m) = map(int, input().split())
language = dict()
for _ in range(m):
	(a, b) = input().split()
	short = ''
	if len(a) <= len(b):
		short = a
	else:
		short = b
	language.update({a: short, b: short})
lecture = list(input().split())
for word in lecture:
	print(language[word], end=' ')


line = input()
line = line.split()
n = int(line[0])
m = int(line[1])
lang = {}
length = {}
for i in range(0, m):
	line = input()
	line = line.split()
	len1 = len(line[0])
	len2 = len(line[1])
	lang[line[0]] = line[1]
	lang[line[1]] = line[0]
	length[line[0]] = len(line[0])
	length[line[1]] = len(line[1])
line = input()
line = line.split()
for i in range(0, n):
	if length[line[i]] > length[lang[line[i]]]:
		line[i] = lang[line[i]]
nstr = ''
for k in line:
	nstr = nstr + k + ' '
print(nstr[:-1])


(n, m) = map(int, input().split(' '))
a = []
b = []
for i in range(m):
	(x, y) = input().split(' ')
	a.append(x)
	b.append(y)
ans = []
s = input().split(' ')
for j in range(len(s)):
	if s[j] in a:
		index = a.index(s[j])
		if len(a[index]) > len(b[index]):
			ans.append(b[index])
		else:
			ans.append(a[index])
	elif s[j] in b:
		index = b.index(s[j])
		if len(a[index]) > len(b[index]):
			ans.append(b[index])
		else:
			ans.append(a[index])
print(' '.join(ans))


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	(l1, l2) = input().split()
	a[l1] = l2
word = input().split()
for i in range(n):
	if word[i] in a and len(word[i]) > len(a[word[i]]):
		print(a[word[i]], end='\n' if i == n - 1 else ' ')
	else:
		print(word[i], end='\n' if i == n - 1 else ' ')


def main():
	(n, m) = map(int, input().split())
	d = {}
	for i in range(m):
		a = list(map(str, input().split()))
		if a[0] not in d:
			d[a[0]] = a[1]
	q = list(map(str, input().split()))
	for i in range(n):
		if len(q[i]) > len(d[q[i]]):
			q[i] = d[q[i]]
	print(*q)
main()


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(d1, d2) = map(str, input().split())
	d[d1] = d2
lec = list(input().split())
for i in range(n):
	print(lec[i] if len(lec[i]) <= len(d[lec[i]]) else d[lec[i]], end=' ')


t = input().split()
n = int(t[0])
m = int(t[1])
d = {}
for i in range(m):
	t = input().split()
	d[t[0]] = t[1]
c = input().split()
for i in range(n - 1):
	k = d[c[i]]
	if len(k) < len(c[i]):
		print(k, end=' ')
	else:
		print(c[i], end=' ')
k = d[c[n - 1]]
if len(k) < len(c[n - 1]):
	print(k)
else:
	print(c[n - 1])


(n, m) = map(int, input().split())
dic = {}
for _ in range(m):
	(a, b) = input().split()
	dic[a] = b
l = [x for x in input().split()]
for x in l:
	if len(x) > len(dic[x]):
		print(dic[x], end=' ')
	else:
		print(x, end=' ')


n = list(map(int, input().split(' ')))
a = []
for i in range(n[1]):
	temp = list(input().split(' '))
	a.append((temp[0], temp[1]))
notes = list(input().split(' '))
dict = {}
for (i, j) in a:
	dict[i] = i if len(i) <= len(j) else j
for i in notes:
	print(dict[i], end=' ')


(n, m) = map(int, input().split())
M = {}
for _ in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		M[a] = b
	else:
		M[a] = a
lec = list(input().split())
for s in lec:
	print(M[s], end=' ')


(n, m) = map(int, input().split())
ls = {}
for _ in range(m):
	line = input().split()
	ls[line[0]] = line[1]
lecture = input().split()
for i in range(len(lecture)):
	word = lecture[i]
	if len(ls[word]) < len(word):
		lecture[i] = ls[word]
print(' '.join(lecture))


(n, m) = map(int, input().split())
d = dict()
for i in range(m):
	(a, b) = input().split()
	d[a] = b if len(b) < len(a) else a
print(' '.join((d[i] for i in input().split())))


(n, m) = map(int, input().split())
words = {}
for i in range(m):
	(word1, word2) = input().split()
	if len(word1) <= len(word2):
		words[word1] = word1
	else:
		words[word1] = word2
lecture = input().strip().split()
s = list(map(lambda x: words[x], lecture))
print(*s)


def ss(s1, s2):
	if len(s1) <= len(s2):
		return s1
	else:
		return s2
(m, n) = list(map(int, input().split(' ')))
di = {}
for i in range(n):
	(s1, s2) = input().split(' ')
	di[s1] = ss(s1, s2)
	di[s2] = ss(s1, s2)
p = input().split(' ')
for i in p:
	print(di[i], end=' ')
print()


(n, k) = map(int, input().split())
a = []
b = []
for _ in range(k):
	(k1, k2) = map(str, input().split())
	a.append(k1)
	b.append(k2)
c = list(input().split())
for i in range(len(c)):
	if c[i] in a:
		t = a.index(c[i])
		if len(a[t]) <= len(b[t]):
			print(a[t], end=' ')
		else:
			print(b[t], end=' ')
	else:
		t = b.index(c[i])
		if len(b[t]) <= len(a[t]):
			print(b[t], end=' ')
		else:
			print(a[t], end=' ')


(n, m) = map(int, input().strip().split())
d = {}
for i in range(m):
	s = input().split(' ')
	s1 = s[0]
	s2 = s[1]
	l1 = len(s1)
	l2 = len(s2)
	if l1 <= l2:
		d[s1] = s1
	else:
		d[s1] = s2
a = input().split(' ')
for i in a:
	print(d[i], end=' ')


def solve(n, m, t, l):
	return ' '.join((w if len(w) <= len(t[w]) else t[w] for w in l))

def main():
	(n, m) = list(map(int, input().split()))
	t = dict((input().split() for _ in range(m)))
	l = input().split()
	print(solve(n, m, t, l))
main()


(a, b) = list(map(int, input().split()))
t = {}
p = []
for i in range(b):
	u = list(input().split())
	t[u[0]] = u[1]
f = input().split()
for j in range(len(f)):
	if len(t[f[j]]) < len(f[j]):
		p.append(t[f[j]])
	else:
		p.append(f[j])
print(*p)


import sys
(n, m) = map(int, sys.stdin.readline().split())
adict = dict()
for _ in range(m):
	(a, b) = sys.stdin.readline().strip().split()
	if len(a) <= len(b):
		adict[a] = a
		adict[b] = a
	else:
		adict[a] = b
		adict[b] = b
s = sys.stdin.readline().strip().split()
print(' '.join([adict[a] for a in s]))


l = [int(x) for x in input().split()]
n = l[0]
m = l[1]
l1 = []
l2 = []
string = ''
l = []
for i in range(m):
	s = input().split(' ')
	l1.append(s[0])
	l2.append(s[1])
	if len(s[0]) < len(s[1]):
		l.append(s[0])
	elif len(s[1]) < len(s[0]):
		l.append(s[1])
	else:
		l.append(s[0])
p = input().split()
for i in range(len(p)):
	if p[i] in l1:
		x = l1.index(p[i])
	else:
		x = l2.index(p[i])
	string = string + l[x] + ' '
print(string)


def minstr(k, v):
	if len(k) <= len(v):
		return k
	return v
	pass
(n, m) = input().split()
M = {}
res = ''
for i in range(int(m)):
	(k, v) = input().split()
	M[k] = v
first = input().split()
for i in first:
	res += minstr(i, M[i])
	res += ' '
print(res)


def s(a, b):
	if len(a) == len(b):
		return a
	elif len(a) < len(b):
		return a
	else:
		return b
(a, b) = map(int, input().split())
dic = dict()
for i in range(b):
	(m, n) = input().split()
	dic[m] = s(m, n)
for i in input().split():
	print(dic[i], end=' ')


(n, m) = map(int, input().split())
words = dict()
for i in range(0, m):
	(k, v) = input().split()
	words[k] = v
print(' '.join((min(w, words[w], key=lambda o: len(o)) for w in input().split())))


import math
import sys
import re
(n, m) = map(int, input().rstrip().split())
l = {}
for x in range(m):
	x = list(input().rstrip().split())
	if x[0] not in l:
		l[x[0]] = x[1]
l1 = list(input().rstrip().split())
l2 = []
for y in l1:
	if len(y) > len(l[y]):
		l2.append(l[y])
	else:
		l2.append(y)
print(' '.join(l2))


(n, m) = (int(x) for x in input().split())
d = dict()
for i in range(m):
	(x, y) = (j for j in input().split())
	d[x] = y
inp = input().split()
for i in inp:
	print(d[i] if len(d[i]) < len(i) else i, '', end='')


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
lecture = input().split()
ans = ''
for word in lecture:
	meaning = d[word]
	if len(meaning) < len(word):
		ans += meaning + ' '
	else:
		ans += word + ' '
print(ans.strip())


arr = list(map(int, input().split()))
(lec, size) = (arr[0], arr[1])
lang1 = []
lang2 = []
for _ in range(size):
	arr1 = list(input().split())
	lang1.append(arr1[0])
	lang2.append(arr1[1])
lecture = list(input().split())
output = []
for i in lecture:
	ind = lang1.index(i)
	if len(lang2[ind]) < len(lang1[ind]):
		output.append(lang2[ind])
	else:
		output.append(i)
str = ' '.join((word for word in output))
print(str)


d = [int(x) for x in input().split(' ')]
c = {}
for x in range(d[1]):
	data = [x for x in input().split(' ')]
	if len(data[0]) <= len(data[1]):
		c[data[0]] = data[0]
	else:
		c[data[0]] = data[1]
s = [x for x in input().split(' ')]
for x in range(d[0]):
	s[x] = c[s[x]]
print(' '.join(s))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = map(str, input().split())
	d[a] = b
h = list(map(str, input().split()))
for i in range(len(h)):
	if len(d[h[i]]) < len(h[i]):
		h[i] = d[h[i]]
print(' '.join(h))


a1 = input().split()
a = list(a1)
d = {}
for i in range(int(a[1])):
	b1 = input().split()
	b = list(b1)
	d[b[0]] = b[1]
c1 = input().split()
c = list(c1)
for i in range(int(a[0])):
	if len(c[i]) <= len(d[c[i]]):
		print(c[i], end=' ')
	else:
		print(d[c[i]], end=' ')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
d = {}
for i in range(m):
	l = input().split()
	if len(l[0]) > len(l[1]):
		key = l[1]
	else:
		key = l[0]
	d[l[0]] = key
	d[l[1]] = key
r = input().split()
for i in r:
	print(d[i], end=' ')


(m, n) = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
	x = [j for j in input().split()]
	a.append(x[0])
	b.append(x[1])
c = [i for i in input().split()]
notes = []
for i in range(len(c)):
	for j in range(len(a)):
		if c[i] == a[j]:
			if len(a[j]) <= len(b[j]):
				notes.append(a[j])
			else:
				notes.append(b[j])
			break
ans = ' '.join(notes)
print(ans)


(n, m) = map(int, input().split())
f = []
s = []
ans = ''
for i in range(m):
	(a, b) = input().split()
	f.append(a)
	s.append(b)
p = input().split()
for word in p:
	i = 0
	if word in f:
		i = f.index(word)
	if word in s:
		i = s.index(word)
	if len(f[i]) < len(s[i]):
		ans += f[i]
	elif len(f[i]) == len(s[i]):
		ans += f[i]
	else:
		ans += s[i]
	ans += ' '
print(ans)


def inp():
	return map(int, input().split(' '))

def findString(word):
	for i in range(m):
		if word == a[i] or word == b[i]:
			if len(a[i]) <= len(b[i]):
				return a[i]
			else:
				return b[i]
(n, m) = inp()
a = []
b = []
for i in range(m):
	(temp1, temp2) = input().split(' ')
	a.append(temp1)
	b.append(temp2)
text = list(input().split(' '))
result_text = ''
for i in range(len(text)):
	text[i] = str(findString(text[i]))
print(' '.join(text))


(n, m) = map(int, input().split())
dict = {}
for i in range(m):
	(key, value) = input().split()
	dict[key] = value
text = [x for x in input().split()]

def lecture(dict, text):
	result = []
	for language1 in text:
		write_down = language1
		language2 = dict[language1]
		if len(language2) < len(language1):
			write_down = language2
		print(write_down, end=' ')
lecture(dict, text)


(n, m) = map(int, input().split())
d = dict(map(lambda _: input().split(), range(m)))
print(' '.join(map(lambda w: min((w, d[w]), key=len), input().strip().split())))


(p, q) = map(int, input().split())
lst = []
lst1 = []
lst2 = []
for i in range(q):
	s = input()
	z = s.index(' ')
	lst.append(s[:z])
	lst1.append(s[z + 1:])
a = input()
q2 = 0
if p != 1:
	for i in range(p - 1):
		z = a.index(' ')
		lst2.append(a[q2:z])
		a = a[:q2] + a[q2:z] + a[z + 1:]
		q2 = z
	lst2.append(a[z:])
else:
	lst2.append(a)
z = []
for i in lst2:
	if i in lst:
		t = lst.index(i)
		if len(lst[t]) > len(lst1[t]):
			z.append(lst1[t])
		else:
			z.append(lst[t])
	if i in lst1:
		t = lst1.index(i)
		if len(lst[t]) > len(lst1[t]):
			z.append(lst1[t])
		else:
			z.append(lst[t])
print(*z)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(w1, w2) = input().split()
	d[w1] = w2 if len(w2) < len(w1) else w1
print(' '.join([d[s] for s in input().split()]))


ins = input().strip().split(' ')
(n, m) = (int(ins[0]), int(ins[1]))
code = {}
for i in range(m):
	ins = input().strip().split(' ')
	code[ins[0]] = ins[1]
ins = input().strip().split(' ')
for i in range(n):
	if len(ins[i]) <= len(code[ins[i]]):
		print(ins[i], end=' ')
	else:
		print(code[ins[i]], end=' ')


(m, n) = map(int, input().split())
l = {}
ans = ''
for f in range(n):
	s = input().split(' ')
	if len(s[0]) <= len(s[1]):
		l[s[0]] = s[0]
		l[s[1]] = s[0]
	else:
		l[s[0]] = s[1]
		l[s[1]] = s[1]
h = input().split(' ')
for f in h:
	ans += l[f] + ' '
print(ans.strip())


inp1 = list(map(int, input().strip().split()))[:2]
(n, m) = (inp1[0], inp1[1])
dict1 = {}
for i in range(m):
	str1 = input()
	k = str1.split(' ')
	dict1[k[0]] = k[1]
str2 = input()
k = str2.split(' ')
l = ''
for i in k:
	if len(i) <= len(dict1[i]):
		l += i
	else:
		l += dict1[i]
	l += ' '
print(l[:-1])


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
s = [i for i in input().split()]
for (i, j) in enumerate(s):
	if len(j) > len(d[j]):
		s[i] = d[j]
for i in s:
	print(i, end=' ')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
c = list(input().split())
for i in range(n):
	if len(a[a.index(c[i])]) <= len(b[a.index(c[i])]):
		print(a[a.index(c[i])], end=' ')
	else:
		print(b[a.index(c[i])], end=' ')


(n, m) = map(int, input().split())
(a, b, ans) = ([], [], [])
for _ in range(m):
	(x, y) = map(str, input().split())
	a.append(x)
	b.append(y)
l = [w for w in input().split()]
for w in l:
	if w in a:
		i = a.index(w)
	else:
		i = b.index(w)
	if len(b[i]) < len(a[i]):
		ans.append(b[i])
	else:
		ans.append(a[i])
print(' '.join(ans))


def make_translator_dictionary(a, b, m):
	translator_dic = {}
	for i in range(m):
		translator_dic[a[i]] = b[i]
	return translator_dic

def make_note(a, b, text_professor, n, m):
	translator_dic = make_translator_dictionary(a, b, m)
	result = ''
	for i in range(n):
		len1 = len(translator_dic[text_professor[i]])
		len2 = len(text_professor[i])
		term = ''
		if len1 > len2:
			term = text_professor[i]
		elif len1 < len2:
			term = translator_dic[text_professor[i]]
		else:
			term = text_professor[i]
		if i == 0:
			result = term
		else:
			result = result + ' ' + term
	return result
(n, m) = [int(x) for x in input().strip().split(' ')]
a = []
b = []
term_array = []
for i in range(1, m + 1):
	term_array = [str(x) for x in input().strip().split(' ')]
	a.append(term_array[0])
	b.append(term_array[1])
text_professor = [str(x) for x in input().strip().split(' ')]
print(make_note(a, b, text_professor, n, m))


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = input().split()
	dic[a] = b
l = list(input().split())
for ele in l:
	if len(ele) <= len(dic[ele]):
		print(ele, end=' ')
	else:
		print(dic[ele], end=' ')


(a, b) = map(int, input().split(' '))
dicx = {}
for _ in range(b):
	(one, two) = input().split(' ')
	if len(one) > len(two):
		dicx[one] = two
	else:
		dicx[one] = one
string = input().split(' ')
for s in string:
	print(dicx[s] + ' ', end='')
print()


a = int(input().split()[1])
b = {}
for i in range(a):
	c = input().split()
	if len(c[1]) < len(c[0]):
		b[c[0]] = c[1]
print(' '.join(map(lambda x: b[x] if x in b else x, input().split())))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(x, y) = map(str, input().split())
	d[x] = (y, 1)
	d[y] = (x, 2)
a = list(map(str, input().split()))
b = []
for i in range(n):
	t1 = a[i]
	t2 = d[a[i]][0]
	if len(t1) < len(t2):
		b.append(t1)
	elif len(t1) == len(t2):
		if d[t1][1] == 1:
			b.append(a[i])
		else:
			b.append(t2)
	else:
		b.append(d[t1][0])
print(*b)


def Lecture(n, m, words, lectureNotes):
	result = []
	for n in lectureNotes:
		if n in words:
			if len(words[n]) < len(n):
				result.append(words[n])
			else:
				result.append(n)
	print(' '.join(result))
(n, m) = [int(x) for x in input().split(' ')]
words = {}
i = 0
while i < m:
	(key, value) = input().split(' ')
	words[key] = value
	i += 1
lectureNotes = input().split(' ')
Lecture(n, m, words, lectureNotes)


(n, m) = list(map(int, input().split()))
d = {}
for i in range(0, m):
	(s1, s2) = list(input().split())
	if len(s1) <= len(s2):
		d[s1] = s1
	else:
		d[s1] = s2
lecture = list(input().split())
for j in range(0, n):
	print(d[lecture[j]], end=' ')


(n, m) = map(int, input().split())
t = []
p = []
for i in range(m):
	arr = list(map(str, input().split()))
	if len(arr[0]) > len(arr[1]):
		t.append(arr[0])
		p.append(arr[1])
	else:
		t.append(arr[1])
		p.append(arr[0])
main = list(map(str, input().split()))
for i in range(n):
	for j in range(len(t)):
		if main[i] == t[j] or main[i] == p[j]:
			print(p[j], end=' ')


(n, m) = map(int, input().split())
c = dict()
for _ in range(m):
	(a, b) = input().split()
	v = min((a, b), key=len)
	c[a] = v
print(*[c[k] for k in input().split()])


(n, m) = map(int, input().split())
short = {}
for _ in range(m):
	(a, b) = input().split()
	short[a] = b if len(b) < len(a) else a
for word in input().split():
	print(short[word], end=' ')


(n, m) = [int(x) for x in input().split()]
dictn = {}
for i in range(m):
	(lang_1, lang_2) = [x for x in input().split()]
	dictn[lang_1] = lang_2
input_string = [x for x in input().split()]
output_string = ''
for i in range(n):
	if len(input_string[i]) <= len(dictn[input_string[i]]):
		output_string = output_string + input_string[i] + ' '
	else:
		output_string = output_string + dictn[input_string[i]] + ' '
print(output_string)


def shorten(word, m, a, b):
	for i in range(m):
		if word == a[i] or word == b[i]:
			if len(a[i]) <= len(b[i]):
				return a[i]
			else:
				return b[i]
(n, m) = map(int, input().split())
(a, b) = ([], [])
for _ in range(m):
	(word1, word2) = input().split()
	a.append(word1)
	b.append(word2)
text = list(input().split())
for word in text:
	word = shorten(word, m, a, b)
	print(word, end=' ')


(n, m) = map(int, input().split())
k = dict((input().split() for i in range(m)))
print(' '.join((min((w, k[w]), key=len) for w in input().split())))


(n, m) = map(int, input().split(' '))
l = [input().split(' ') for i in range(m)]
sentence = input().split(' ')

def chooseLang(l1, l2):
	if len(l1) > len(l2):
		return l2
	return l1
words = []
for i in l:
	words.append(i[0])
	words.append(i[1])
lang = [chooseLang(i[0], i[1]) for i in l]
encryp_lang = ' '.join([i + ' ' + i for i in lang]).split(' ')
print(' '.join([encryp_lang[words.index(w)] for w in sentence if w in words]))


from math import *
mod = 1000000007

def binpow(a, b):
	global mod
	if b == 1:
		return a % mod
	u = binpow(a, b // 2)
	if b % 2 == 0:
		return u * u % mod
	else:
		return u * u * a % mod

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
dic = {}
for _ in range(1):
	(n, m) = [int(i) for i in input().split()]
	for i in range(m):
		(a, b) = input().split()
		if len(a) > len(b):
			dic[a] = b
		else:
			dic[a] = a
	s = [dic[i] for i in input().split()]
	print(' '.join(s))


a = input().split()
n = int(a[0])
m = int(a[1])
dic = {}
for i in range(m):
	a = input().split()
	dic[a[0]] = a[1]
state = input().split()
ans = []
for i in state:
	if len(dic[i]) < len(i):
		ans.append(dic[i])
	else:
		ans.append(i)
print(' '.join(ans))


(n, m) = map(int, input().split())
f = []
s = []
for i in range(m):
	(a, b) = map(str, input().split())
	f.append(a)
	s.append(b)
l = list(map(str, input().split()))
for i in range(n):
	if l[i] in f:
		c = f.index(l[i])
		if len(f[c]) > len(s[c]):
			l[i] = s[c]
	elif l[i] in s:
		c = s.index(l[i])
		if len(s[c]) >= len(f[c]):
			l[i] = f[c]
print(' '.join(l))


(a, b) = map(int, input().strip().split())
lang1 = []
lang2 = []
for _ in range(b):
	l = list(map(str, input().strip().split()))
	lang1.append(l[0])
	lang2.append(l[1])
lecture = list(map(str, input().split()))
for i in lecture:
	indexInLang1 = lang1.index(i)
	if len(lang1[indexInLang1]) > len(lang2[indexInLang1]):
		print(lang2[indexInLang1], end=' ')
	else:
		print(lang1[indexInLang1], end=' ')


(n, m) = map(int, input().rstrip().split(' '))
l = []
k = []
r = ''
while m:
	(f, g) = input().split(' ')
	l.append(f)
	k.append(g)
	m -= 1
chek = input().split(' ')
for i in chek:
	t = l.index(i)
	if len(l[t]) > len(k[t]):
		r = r + ' ' + k[t]
	else:
		r = r + ' ' + l[t]
print(r[1:])


inp = input().split()
(n, m) = (int(inp[0]), int(inp[1]))
d = {}
for i in range(0, m):
	L = input().split()
	(x, y) = (L[0], L[1])
	if len(y) < len(x):
		d[x] = y
	else:
		d[x] = x
lec = input().split()
for w in lec:
	print(d[w], end=' ')


import sys
nm = list(map(int, sys.stdin.readline().split()))
n = nm[0]
m = nm[1]
lr = []
for i in range(0, m):
	g = sys.stdin.readline().split()
	if len(g[0]) <= len(g[1]):
		gg = g[0]
	else:
		gg = g[1]
	lr = lr + [[g[0], g[1], gg]]
lr = sorted(lr)
q = sys.stdin.readline().split()
r = ''
for j in q:
	for x in lr:
		if j == x[0]:
			r = r + x[2] + ' '
			break
print(r)


(lectureW, languageW) = map(int, input().split())
(lang1, lang2) = ([], [])
for i in range(languageW):
	(x, y) = input().split()
	lang1.append(x)
	lang2.append(y)
message = input().split()
for w in range(lectureW):
	if len(lang1[lang1.index(message[w])]) > len(lang2[lang1.index(message[w])]):
		message[w] = lang2[lang1.index(message[w])]
print(' '.join((str(i) for i in message)))


(n, m) = map(int, input().split())
d = {}
for x in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	elif len(a) > len(b):
		d[a] = b
i = input().split()
o = []
for x in i:
	o.append(d[x])
print(*o)


(n, m) = map(int, input().split())
lan = {}
for _ in range(m):
	t = input().split()
	lan[t[0]] = t[1]
wor = list(input().split())
sol = []
for i in wor:
	if len(lan[i]) < len(i):
		sol.append(lan[i])
	else:
		sol.append(i)
print(*sol)


ans = []
(n, m) = map(int, input().strip().split())
lis = []
for _ in range(m):
	arr = list(input().split())
	lis.append(arr)
c = list(input().split())
for i in range(n):
	for j in range(len(lis)):
		if lis[j][0] == c[i]:
			if len(lis[j][0]) <= len(lis[j][1]):
				ans.append(lis[j][0])
			else:
				ans.append(lis[j][1])
		elif lis[j][1] == c[i]:
			if len(lis[j][0]) <= len(lis[j][1]):
				ans.append(lis[j][0])
			else:
				ans.append(lis[j][1])
print(*ans)


def answer(n, m, a, b, c):
	new_ary = []
	for i in range(len(c)):
		indx = a.index(c[i])
		if len(a[indx]) <= len(b[indx]):
			new_ary.append(a[indx])
		else:
			new_ary.append(b[indx])
	return ' '.join(new_ary)

def answer2(c, d):
	new_ary = []
	for e in c:
		if len(e) <= len(d[e]):
			new_ary.append(e)
		else:
			new_ary.append(d[e])
	return ' '.join(new_ary)

def main():
	(n, m) = [int(i) for i in input().split()]
	a = ['x'] * m
	b = ['x'] * m
	d = {}
	for j in range(m):
		(a[j], b[j]) = [i for i in input().split()]
	d = {k: v for (k, v) in zip(a, b)}
	c = [i for i in input().split()]
	print(answer2(c, d))
main()


(n, m) = map(int, input().split())
c = {}
d = []
for i in range(m):
	(a, b) = input().split()
	c[a] = b
text = input().split()
for i in text:
	if len(c[i]) < len(i):
		d.append(c[i])
	else:
		d.append(i)
print(' '.join(d))


L1 = input().split()
n = int(L1[0])
m = int(L1[1])
word = {}
c = ' '
for i in range(m):
	inp = input().split()
	fir = inp[0]
	word[fir] = {}
	word[fir] = inp[1]
L = input().split()
for i in range(len(L)):
	fir = L[i]
	if len(fir) > len(word[fir]):
		L[i] = word[fir]
c = ' '
for i in range(len(L) - 1):
	print(L[i] + c, end='')
print(L[len(L) - 1])


M = dict()
(n, m) = map(int, input().split())
for i in range(m):
	(s, t) = input().split()
	if len(s) < len(t):
		(s, t) = (t, s)
	elif len(s) == len(t):
		s = t
	M[s] = t
a = list(input().split())
for word in a:
	if word in M:
		print(M[word], end=' ')
	else:
		print(word, end=' ')


def lecture():
	(n, m) = [int(i) for i in input().split()]
	(a, b) = ([], [])
	for i in range(m):
		inp = input().split()
		a.append(inp[0])
		b.append(inp[1])
	prof = input().split()
	for i in prof:
		tt = b[a.index(i)]
		if len(i) > len(tt):
			print(tt)
		else:
			print(i)
	return
lecture()


(n, m) = list(map(int, input().split()))
di = {}
for i in range(m):
	(a, b) = map(str, input().split())
	di[a] = b
ss = input().split()
k = []
for j in ss:
	val = di[j]
	if len(val) < len(j):
		k.append(val)
	else:
		k.append(j)
print(' '.join(k))


(n, m) = map(int, input().split())
l = []
for i in range(m):
	l = l + list(input().split())
a = list(input().split())
for i in range(0, n):
	t = l.index(a[i])
	if t % 2 == 0:
		if len(l[t]) <= len(l[t + 1]):
			print(l[t], end=' ')
		else:
			print(l[t + 1], end=' ')
print()


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = input().split()
	dic[a] = a
	if len(a) > len(b):
		dic[a] = b
text = input().split()
for word in text:
	print(dic[word], end=' ')


(lection_size, dictionary_size) = map(int, input().split())
language_dict = {}
for _ in range(dictionary_size):
	(lection_word, translation) = input().split()
	language_dict[lection_word] = translation
lection_words = input().split()
for word in lection_words:
	word_abbr = language_dict[word]
	result_word = min(word, word_abbr, key=len)
	print(result_word, end=' ')


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(l1, l2) = input().split()
	if len(l1) > len(l2):
		d[l1] = l2
	else:
		d[l1] = l1
string = input()
for word in string.split():
	print(d[word], end=' ')
print()


c = 0
(m, n) = input().split(' ')
(m, n) = (int(m), int(n))
dict1 = {}
for i in range(n):
	(a, b) = input().split(' ')
	dict1[a] = b
s = input().split(' ')
for i in s:
	if len(i) <= len(dict1[i]):
		print(i, end=' ')
	else:
		print(dict1[i], end=' ')


inp = input()
a = inp.split()
for i in range(0, len(a)):
	a[i] = int(a[i])
dic = {}
for i in range(0, a[1]):
	inp2 = input()
	b = inp2.split()
	dic[b[0]] = b[1]
inp3 = input()
c = inp3.split()
final = []
for i in c:
	if len(i) > len(dic[i]):
		final.append(dic[i])
	else:
		final.append(i)
for i in final:
	print(i)


a = list(map(int, input().split()))
n = a[0]
m = a[1]
d = {}
for i in range(0, m):
	x = list(input().split())
	if len(x[0]) <= len(x[1]):
		c = 0
	else:
		c = 1
	d[x[0]] = x[c]
y = list(input().split())
l = []
for i in y:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
a = [[str(x) for x in input().split()] for i in range(m)]
b = input().split()
c = {}
for j in range(len(a)):
	if len(a[j][0]) <= len(a[j][1]):
		c[a[j][0]] = a[j][0]
		c[a[j][1]] = a[j][0]
	else:
		c[a[j][0]] = a[j][1]
		c[a[j][1]] = a[j][1]
for p in range(len(b)):
	b[p] = c[b[p]]
print(' '.join(b))


(n, m) = list(map(int, input().split()))
a = []
b = []
for i in range(0, m):
	s = input()
	s = s.split()
	a.append(s[0])
	b.append(s[1])
l = input()
l = l.split(' ')
w = ''
for i in l:
	p = a.index(i)
	if len(a[p]) <= len(b[p]):
		w = w + a[p] + ' '
	else:
		w = w + b[p] + ' '
print(w[:-1])


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d[a] = a if len(a) <= len(b) else b
print(' '.join((d[x] for x in input().split())))


X = list(map(int, input().split()))
MyDict = dict()
for i in range(X[1]):
	Y = list(input().split())
	MyDict[Y[0]] = Y[1]
Sentence = list(input().split())
for i in Sentence:
	if len(MyDict[i]) < len(i):
		print(MyDict[i], end=' ')
		continue
	print(i, end=' ')


(i, j) = [int(x) for x in input().split(' ')]
n = 0
l1 = list()
l2 = list()
while n < j:
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
	n = n + 1
s = list(input().split())
ans = list()
for i in s:
	if i in l1:
		if len(l1[l1.index(i)]) <= len(l2[l1.index(i)]):
			ans.append(l1[l1.index(i)])
		else:
			ans.append(l2[l1.index(i)])
	elif len(l1[l2.index(i)]) <= len(l2[l2.index(i)]):
		ans.append(l1[l2.index(i)])
	else:
		ans.append(l2[l2.index(i)])
print(' '.join(ans))


(m, n) = map(int, input().split())
dec = []
for i in range(n):
	(a, b) = map(str, input().split())
	alen = len(a)
	blen = len(b)
	temp = []
	temp.append(a)
	temp.append(b)
	if alen <= blen:
		temp.append(a)
	else:
		temp.append(b)
	dec.append(temp)
word = ''
stat = list(map(str, input().split()))
for i in stat:
	for array in dec:
		if array[1] == i or array[0] == i:
			word += array[2] + ' '
print(word)


(a, b) = map(int, input().split())
c = []
for i in range(b):
	c.append(input().split())
e = [i[0] for i in c]

def small_word(i):
	if len(i[0]) <= len(i[1]):
		return i[0]
	else:
		return i[1]
d = input().split()
for i in range(len(d)):
	f = e.index(d[i])
	d[i] = small_word(c[f])
print(' '.join(d))


(n, m) = map(int, input().split())
l = []
for i in range(0, m):
	l.append([j for j in input().split()])
s = []
s = input().split()
s2 = ''
for i in range(0, n):
	for j in range(0, m):
		if s[i] == l[j][0] or s[i] == l[j][1]:
			if len(l[j][0]) > len(l[j][1]):
				s2 += l[j][1]
			elif len(l[j][0]) == len(l[j][1]):
				s2 += l[j][0]
			else:
				s2 += l[j][0]
	s2 += ' '
print(s2)


(n, m) = [int(x) for x in input().split(' ')]
d = {}

def s(a, b):
	if len(a) < len(b):
		return a
	elif len(a) > len(b):
		return b
	else:
		return a
for i in range(m):
	(a, b) = [x for x in input().split(' ')]
	f = s(a, b)
	d[a] = f
	d[b] = f
l = [s for s in input().split(' ')]
for i in range(len(l)):
	l[i] = d[l[i]]
s = ' '.join(l)
print(s)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m) = LI()
	a = [LS() for _ in range(m)]
	s = LS()
	d = {}
	for (e, f) in a:
		t = f
		if len(e) <= len(f):
			t = e
		d[e] = t
		d[f] = t
	r = []
	for c in s:
		r.append(d[c])
	return ' '.join(map(str, r))
print(main())


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd, log10, atan, tan

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_strs():
	return map(str, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m) = get_ints()
mydict = dict()
for i in range(m):
	(str1, str2) = get_strs()
	mydict[str1] = str2
lecture = input().split()
for i in range(n):
	if len(lecture[i]) > len(mydict[lecture[i]]):
		lecture[i] = mydict[lecture[i]]
print(*lecture)


seq = input()
A = seq.split()
n = int(A[0])
m = int(A[1])
guide = {}
for i in range(m):
	seq = input()
	A = seq.split()
	if len(A[0]) < len(A[1]):
		key = A[1]
		res = A[0]
	elif len(A[0]) == len(A[1]):
		key = A[1]
		res = A[0]
	else:
		key = A[0]
		res = A[1]
	guide[key] = res
seq = input()
A = seq.split()
B = []
for i1 in A:
	if i1 in guide.keys():
		B.append(guide[i1])
	else:
		B.append(i1)
print(' '.join(B))


(n, m) = map(int, input().split())
(z, z1) = ([], [])
ans = []
for i in range(m):
	(x, y) = map(str, input().split())
	z.append(min(x, y))
	z1.append(max(x, y))
l = list(map(str, input().split()))
for i in range(n):
	if l[i] in z:
		b = z.index(l[i])
		if len(l[i]) <= len(z1[b]):
			ans.append(l[i])
		else:
			ans.append(z1[b])
	if l[i] in z1:
		b = z1.index(l[i])
		if len(l[i]) <= len(z[b]):
			ans.append(l[i])
		else:
			ans.append(z[b])
print(*ans)


import time, math
from sys import stdin, stdout

def In():
	return map(int, stdin.readline().split())

def Is():
	return map(str, stdin.readline().split())

def L():
	return list(map(str, stdin.readline().split()))

def Si():
	return sorted(list(map(int, stdin.readline().split())))

def Si():
	return sorted(list(map(int, stdin.readline().split())), reverse=True)

def P(x):
	return stdout.write(str(x) + ' ')

def Pi(x, y):
	return stdout.write(str(x) + ' ' + str(y))

def solve():
	(n, m) = In()
	d = {}
	for i in range(m):
		(a, b) = Is()
		d[a] = b
	l = L()
	for i in l:
		s1 = len(i)
		if s1 > len(d[i]):
			P(d[i])
		else:
			P(i)
solve()


(n, m) = map(int, input().split())
lst1 = []
lst2 = []
for i in range(m):
	(x, y) = map(str, input().split(' '))
	lst1.append(x)
	lst2.append(y)
lst3 = list(map(str, input().split(' ')))
lst4 = []
for i in lst3:
	a = lst1.index(i)
	if len(lst1[a]) <= len(lst2[a]):
		lst4.append(lst1[a])
	else:
		lst4.append(lst2[a])
for i in range(len(lst4)):
	print(lst4[i], end=' ')


(n, m) = map(int, input().split())
vocab_first = {}
vocab_joined = {}
shortest_version = []
for _ in range(m):
	(a, b) = input().split()
	vocab_first[a] = b
	vocab_joined[a] = b
	vocab_joined[b] = a
for w in input().split():
	if len(vocab_joined[w]) < len(w):
		shortest_version.append(vocab_joined[w])
	elif len(w) < len(vocab_joined[w]):
		shortest_version.append(w)
	elif w in vocab_first:
		shortest_version.append(w)
	else:
		shortest_version.append(vocab_joined[w])
print(' '.join(shortest_version))


(n, m) = [int(i) for i in input().split()]
a1 = []
b = []
for a0 in range(m):
	a = input().split()
	a1.append(a[0])
	b.append(a[1] if len(a[1]) < len(a[0]) else a[0])
notes = input().split()
for word in notes:
	print(b[a1.index(word)], end=' ')


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, m) = iia()
d = {}
for _ in range(m):
	(a, b) = isa()
	d[a] = b
ans = []
for t in isa():
	if len(t) <= len(d[t]):
		ans.append(t)
	else:
		ans.append(d[t])
print(*ans, sep=' ')


(n, m) = map(int, input().split())
k = []
os = ''
for i in range(m):
	s = input()
	l = s.strip().split()
	k.append(l)
stri = input()
strl = stri.strip().split()
for i in strl:
	for j in k:
		if i == j[0]:
			c1 = len(j[0])
			c2 = len(j[1])
			if c1 > c2:
				os = os + j[1] + ' '
			else:
				os = os + j[0] + ' '
print(os[:-1], end='')


(n, m) = map(int, input().split(' '))
d = {}
for i in range(m):
	s = input().split(' ')
	l1 = len(s[0])
	l2 = len(s[1])
	d[s[0]] = s[1]
	d[s[1]] = s[0]
	if l1 > l2:
		d[s[1]] = s[1]
	else:
		d[s[0]] = s[0]
k = input().split(' ')
for i in k:
	print(d[i], end=' ')


(_, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
a = ''
for i in input().split():
	if len(i) <= len(d[i]):
		a += i + ' '
	else:
		a += d[i] + ' '
print(a.rstrip())


(n, m) = map(int, input().split())
f = []
s = []
g = ''
for i in range(m):
	(a, b) = map(str, input().split())
	f.append(a)
	s.append(b)
c = list(map(str, input().split()))
for i in range(n):
	if c[i] in f:
		x = f.index(c[i])
		if len(f[x]) <= len(s[x]):
			g += f[x] + ' '
		else:
			g += s[x] + ' '
	else:
		x = s.index(c[i])
		if len(s[x]) <= len(f[x]):
			g += s[x] + ' '
		else:
			g += f[x] + ' '
print(g)


(n, m) = map(int, input().split())
d = dict((input().split() for _ in range(m)))
S = input().split()
print(' '.join((min((w, d[w]), key=len) for w in S)))


def solve(dict, sentence):
	notesSentence = []
	for word in sentence:
		mappedWord = dict[word]
		if len(mappedWord) < len(word):
			notesSentence.append(mappedWord)
		else:
			notesSentence.append(word)
	return ' '.join(notesSentence)
(n, m) = map(int, input().split(' '))
dict = {}
for _m in range(0, m):
	words = input().split(' ')
	dict[words[0]] = words[1]
sentence = input().split(' ')
print(solve(dict, sentence))


d = {}
(n, m) = map(int, input().split())
w = []
for i in range(m):
	(a, b) = input().split()
	d[a] = b
c = list(input().split())
for i in range(len(c)):
	m = d[c[i]]
	if len(c[i]) <= len(m):
		print(c[i], end=' ')
	else:
		print(m, end=' ')


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
for _ in range(T):
	(n, m) = list(map(int, stdin.readline().split()))
	d = {}
	for i in range(m):
		s = str(input()).split(' ')
		if len(s[0]) > len(s[1]):
			d[s[0]] = s[1]
			d[s[1]] = s[1]
		else:
			d[s[0]] = s[0]
			d[s[1]] = s[0]
	l = str(input()).split(' ')
	for i in l:
		print(d[i], end=' ')
	print()


(n, m) = list(map(int, input().rstrip().split()))
a = []
b = []
for _ in range(m):
	x = list(map(str, input().rstrip().split()))
	a += [x[0]]
	b += [x[1]]
c = list(map(str, input().rstrip().split()))
for i in range(n):
	d = c[i]
	x = a.index(d)
	y = b[x]
	if len(d) <= len(y):
		print(d, end=' ')
	else:
		print(y, end=' ')


(n, m) = map(int, input().split())
dic = {}
while m > 0:
	(key, value) = input().split()
	dic[key] = value
	m -= 1
l = list(input().split())
for el in l:
	if len(el) <= len(dic[el]):
		print(el, sep=' ', end=' ')
	else:
		print(dic[el], sep=' ', end=' ')


from sys import stdin, stdout
(n, q) = map(int, stdin.readline().strip().split())
mydict = dict()
for i in range(q):
	(s1, s2) = map(str, input().split())
	mydict[s1] = s2
mylist = input().split()
result = []
for i in range(n):
	if len(mylist[i]) <= len(mydict[mylist[i]]):
		result.append(mylist[i])
	else:
		result.append(mydict[mylist[i]])
print(*result, sep=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
ans = []
C = input().split()
for i in range(n):
	ans.append(d[C[i]])
print(' '.join(ans))


n_and_m = list(map(int, input().split()))
list_of_words_in_both_language = []
for i in range(n_and_m[1]):
	temp = list(map(str, input().split()))
	list_of_words_in_both_language.append(temp)
given_words = list(map(str, input().split()))
teacher_words = []
short_word = []
for i in list_of_words_in_both_language:
	temp = i[0]
	if len(i[0]) > len(i[1]):
		temp_short = i[1]
	else:
		temp_short = i[0]
	teacher_words.append(temp)
	short_word.append(temp_short)
for i in given_words:
	temp = teacher_words.index(i)
	print(short_word[temp], ' ', end='')


nm = list(map(int, input().split()))
words = []
for i in range(nm[1]):
	words.append(list(map(str, input().split())))
c = list(map(str, input().split()))
res = []
for i in range(nm[0]):
	for j in range(nm[1]):
		if c[i] == words[j][0]:
			if len(words[j][0]) <= len(words[j][1]):
				res.append(words[j][0])
			else:
				res.append(words[j][1])
print(*res)


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
(n, m) = get_int()
ans = {}
for i in range(m):
	t = input().split()
	ans[t[0]] = t[1]
q = input().split()
for i in q:
	print([i, ans[i]][len(i) > len(ans[i])], end=' ')


def lenmin(a, b):
	if len(a) > len(b):
		return b
	return a
(n, m) = (int(i) for i in input().split())
dic = {}
for i in range(m):
	(a, b) = (i for i in input().split())
	dic[a] = lenmin(a, b)
lecture = [i for i in input().split()]
for i in lecture:
	print(dic[i], end=' ')
print()


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d[a] = b if len(b) < len(a) else a
string = []
for word in input().split():
	string.append(d[word])
print(' '.join(string))


(n, m) = (int(i) for i in input().split())
pool = {}
for i in range(m):
	(lang1, lang2) = input().split()
	pool[lang1] = lang2
text = input().split()
for (n, word) in enumerate(text):
	if len(pool[word]) < len(word):
		text[n] = pool[word]
print(' '.join(text))


(n, m) = map(int, input().split())
(fl, sl) = ([], [])
for i in range(m):
	(y, z) = input().split()
	fl.append(y)
	sl.append(z)
s = list(input().split())
for i in s:
	j = fl.index(i)
	if len(fl[j]) == len(sl[j]):
		i = fl[j]
	elif len(fl[j]) < len(sl[j]):
		i = fl[j]
	else:
		i = sl[j]
	print(i, end=' ')


def intput():
	return [int(x) for x in input().split(' ')]

def main(lecture, mapping):
	ans = []
	for word in lecture:
		ans.append(mapping[word])
	print(' '.join(ans))

def parse():
	(_, words) = intput()
	mapping = {}
	for _ in range(words):
		(l1, l2) = input().split(' ')
		lm = l2 if len(l2) < len(l1) else l1
		mapping[l1] = lm
	lecture = input().split(' ')
	return (lecture, mapping)
main(*parse())


(n, m) = [int(x) for x in input().split()]
dict = {}
record = []
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		note = b
	else:
		note = a
	dict[a] = note
lecture = input().split()
for word in lecture:
	d = dict[word]
	record.append(d)
for item in record:
	print(item, end=' ')


(n, m) = map(int, input().split())
d = {}
for k in range(m):
	(a, b) = list(input().split())
	d[a] = b
l = list(input().split())
for i in l:
	if len(i) > len(d[i]):
		print(d[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = list(map(int, input().split()))
a = []
b = []
c = []
res = []
for i in range(m):
	w = input().split()
	a.append(w[0])
	b.append(w[1])
c = input().split()
for i in c:
	k = a.index(i)
	if len(a[k]) <= len(b[k]):
		res.append(a[k])
	else:
		res.append(b[k])
print(' '.join(res))


m = int(input().split()[1])
aa = []
for i in range(m):
	aa += input().split()
st = input().split()
ans = ''
for x in st:
	ind = aa.index(x)
	if ind % 2 == 0:
		fi = 1
	else:
		fi = -1
	if fi == 1:
		ans += [aa[ind], aa[ind + fi]][len(aa[ind]) > len(aa[ind + fi])]
	else:
		ans += [aa[ind + fi], aa[ind]][len(aa[ind + fi]) > len(aa[ind])]
	ans += ' '
print(ans)


(n, m) = map(int, input().split(' '))
words = {}
for i in range(m):
	(a, b) = input().split(' ')
	words[a] = b
arr = list(input().split(' '))
for (i, j) in enumerate(arr):
	if len(words[j]) < len(j):
		arr[i] = words[j]
print(*arr)


(readText, NumOfWords) = [int(x) for x in input().split()]
aDict = {}
for i in range(NumOfWords):
	aWord = input().split()
	aDict[aWord[0]] = aWord[1]
readText = input().split()
for i in range(len(readText)):
	if len(readText[i]) > len(aDict[readText[i]]):
		readText[i] = aDict[readText[i]]
readText = ' '.join(readText)
print(readText)


def lecture(language_mapper, lecture_list):
	final_languages = []
	for language in lecture_list:
		if language in language_mapper:
			if len(language) <= len(language_mapper[language]):
				final_languages.append(language)
			elif len(language) > len(language_mapper[language]):
				final_languages.append(language_mapper[language])
			else:
				pass
	return final_languages
X = str(input())
(n, m) = X.split(' ')
language_mapper = {}
for i in range(int(m)):
	L = str(input())
	(lang1, lang2) = L.split(' ')
	(lang1, lang2) = (lang1.lower(), lang2.lower())
	language_mapper[str(lang1)] = str(lang2)
lecture_list = []
LL = str(input())
lecture_list = LL.split(' ')
lecture_list = [lang.lower() for lang in lecture_list]
final = lecture(language_mapper, lecture_list)
for lang in final:
	print(lang, end=' ')


(n, m) = map(int, input().split())
(d, rev) = (dict(), dict())
for i in range(m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		d[a] = b
		rev[b] = a
	else:
		d[b] = a
		rev[a] = b
arr = list(map(str, input().split()))
for i in arr:
	if i in d.values():
		print(rev[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = list(map(int, input().split()))
b = {}
h = []
for i in range(m):
	x = list(map(str, input().split()))
	if len(x[0]) == len(x[1]):
		b[x[0]] = x[0]
		b[x[1]] = x[0]
	elif len(x[0]) > len(x[1]):
		b[x[0]] = x[1]
		b[x[1]] = x[1]
	elif len(x[0]) < len(x[1]):
		b[x[0]] = x[0]
		b[x[1]] = x[0]
lecture = input()
lecture = lecture.split()
for j in range(n):
	h.append(b[lecture[j]])
print(*h)


(n, m) = list(map(int, input().split()))
d = {}
for i in range(m):
	(k, v) = input().split()
	d[k] = v
s = input().split()
for (n, i) in enumerate(s):
	if len(d[i]) < len(i):
		s[n] = d[i]
print(' '.join(s))


(n, m) = map(int, input().split())
res1 = []
res2 = []
for i in range(m):
	(a, b) = input().split()
	res1.append(a)
	res2.append(b)
ip = list(input().split())
ans = ''
for i in range(len(ip)):
	if ip[i] in res1 or ip[i] in res2:
		j = res1.index(ip[i])
		if len(res1[j]) <= len(res2[j]):
			ans += res1[j] + ' '
		else:
			ans += res2[j] + ' '
print(ans)


a = input()
a = a.split()
n = int(a[0])
m = int(a[1])
k1 = []
k2 = []
for i in range(m):
	l = input()
	l = l.split()
	k1.append(l[0])
	k2.append(l[1])
ans = input()
ans = ans.split()
for i in range(n):
	b = ans[i]
	if k1.count(b) != 0:
		l = len(b)
		j = k1.index(b)
		c = k2[j]
		if len(b) <= len(c):
			ans[i] = b
		else:
			ans[i] = c
	else:
		l = len(b)
		j = k2.index(b)
		c = k1[j]
		if len(b) <= len(c):
			ans[i] = b
		else:
			ans[i] = c
ans1 = ''
for i in range(n):
	ans1 += ans[i] + ' '
print(ans1)


from collections import defaultdict
d = defaultdict(list)
(n, m) = map(int, input().split())
for i in range(m):
	(x, y) = map(str, input().split())
	if len(x) > len(y):
		d[x].append(y)
	else:
		d[x].append(x)
s = list(map(str, input().split()))
for i in range(n):
	print(*d[s[i]], end=' ')


import sys

def main():
	(n, m) = [int(i) for i in input().split()]
	words = {}
	for k in range(m):
		(l1, l2) = [word for word in input().split()]
		words[l1] = [l1, l2]
	lec = input().split()
	for word in lec:
		print(words[word][0] if len(words[word][0]) <= len(words[word][1]) else words[word][1], end=' ')
main()


(n, m) = map(int, input().split())
s = {}
for i in range(m):
	stemp = input().split()
	s[stemp[0]] = stemp[1]
	s[stemp[1]] = stemp[0]
st = input().split()
for i in range(len(st)):
	if i == len(st) - 1:
		if len(s[st[i]]) >= len(st[i]):
			print(st[i])
		else:
			print(s[st[i]])
	elif len(s[st[i]]) >= len(st[i]):
		print(st[i], end=' ')
	else:
		print(s[st[i]], end=' ')


(n, m) = list(map(int, input().split()))
s = {}
for i in range(m):
	(a, b) = input().split()
	s[a] = b if len(b) < len(a) else a
print(' '.join((s[i] for i in input().split())))


arr = [int(x) for x in input().split()]
(n, m) = (arr[0], arr[1])
d = {}
for i in range(m):
	s = input().split()
	(l1, l2) = (s[0], s[1])
	d[l1] = l2
s = input().split()
ans = ''
for ele in s:
	if len(ele) <= len(d[ele]):
		ans += ele + ' '
	else:
		ans += d[ele] + ' '
print(ans)


(n, m) = map(int, input().split())
A = {}
for i in range(m):
	(x, y) = map(str, input().split())
	if len(x) <= len(y):
		A[x] = x
	else:
		A[x] = y
B = [str(i) for i in input().split()]
for i in B:
	print(A[i], end=' ')


(n, m) = map(int, input().split())
l1 = []
l2 = []
for _ in range(m):
	(a, b) = map(str, input().split())
	l1.append(a)
	l2.append(b)
s = ''
list1 = map(str, input().split())
for i in list1:
	if i in l1:
		p = l1.index(i)
		if len(l1[p]) > len(l2[p]):
			s += l2[p] + ' '
		else:
			s += l1[p] + ' '
print(s)


(len_sentence, ln_words) = map(int, input().split())
words = {}
for i in range(ln_words):
	(lang1, lang2) = input().split()
	words[lang1] = lang1 if len(lang1) <= len(lang2) else lang2
sentence = input().split()
written_sentence = []
for word in sentence:
	written_sentence.append(words[word])
print(' '.join(written_sentence))


(n, m) = map(int, input().split())
dictry = {}
for word in range(m):
	(w1, w2) = input().split()
	dictry[w1] = w1 if len(w1) <= len(w2) else w2
lecture = input().split()
lecture = [dictry[x] for x in lecture]
print(' '.join(lecture))


(m, n) = map(int, input().split())
inter = {}
for i in range(n):
	(a, b) = input().split()
	if len(a) <= len(b):
		inter[a] = a
		inter[b] = a
	else:
		inter[a] = b
		inter[b] = b
c = input().split()
for i in range(m):
	print(inter[c[i]], end=' ')


(n, m) = map(int, input().split())
langDict = {}
for i in range(m):
	t = input().split()
	langDict[t[0]] = t[1]
lecture = input().split()
notes = ''
for i in lecture:
	if len(langDict[i]) < len(i):
		notes += langDict[i] + ' '
	else:
		notes += i + ' '
print(notes)


(n, m) = map(int, input().split(' '))
words = dict()
for i in range(0, m):
	(u, v) = input().split(' ')
	words[u] = v
txt = input().split(' ')
note = []
for u in txt:
	v = words[u]
	if len(v) < len(u):
		u = v
	note.append(u)
print(' '.join(note))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
lect = input().split()
for elem in lect:
	print(d[elem], end=' ')


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	tmp = input().split()
	d[tmp[0]] = tmp[1]
s = input().split()
for i in range(n):
	if len(s[i]) > len(d[s[i]]):
		s[i] = d[s[i]]
print(' '.join(s))


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	(s1, s2) = map(str, input().split())
	a[s1] = s2
b = list(map(str, input().split()))
for i in b[0:-1]:
	if len(i) <= len(a[i]):
		print(i, end=' ')
	else:
		print(a[i], end=' ')
i = b[-1]
if len(i) <= len(a[i]):
	print(i, end=' ')
else:
	print(a[i], end=' ')


(n, m) = map(int, input().split())
d = dict((input().split() for _ in range(m)))
print(' '.join((s if len(s) <= len(d[s]) else d[s] for s in input().split())))


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = input().split()
	if len(b) < len(a):
		dic[a] = b
lst = input().split()
for x in lst:
	if x in dic:
		print(dic[x], end=' ')
	else:
		print(x, end=' ')


(n, m) = map(int, input().split())
s = dict()
for i in range(m):
	(a, s[a]) = map(str, input().split())
c = input().split()
for i in range(n):
	if len(c[i]) > len(s[c[i]]):
		print(s[c[i]])
	else:
		print(c[i])


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d[a] = b
	d[b] = a
c = list(input().split())
res = []
for w in c:
	m = w if len(w) <= len(d[w]) else d[w]
	res.append(m)
print(*res)


(n, m) = list(map(int, input().split()))
(a, b) = ([], [])
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
lecture = input().split()
onetotwo = {}
twotoone = {}
for i in range(m):
	onetotwo[a[i]] = b[i]
	twotoone[b[i]] = a[i]
ans = []
for word in lecture:
	if word in onetotwo:
		(k, v) = (word, onetotwo[word])
		if len(k) <= len(v):
			ans.append(k)
		else:
			ans.append(v)
	else:
		(k, v) = (word, twotoone[word])
		if len(k) < len(v):
			ans.append(k)
		else:
			ans.append(v)
print(' '.join(ans))


(n, m) = map(int, input().split(' '))
d = {}
for _ in range(m):
	line = input().split()
	if len(line[0]) > len(line[1]):
		d[line[0]] = line[1]
	else:
		d[line[0]] = line[0]
lec = input().split()
res = ''
for i in lec:
	res += d[i] + ' '
print(res)


(n, m) = str(input()).split()
n = int(n)
m = int(m)
list_a = list()
list_b = list()
for i in range(m):
	(a, b) = str(input()).split()
	list_a.append(a)
	list_b.append(b)
list_c = str(input()).split()
for i in range(n):
	idx = list_a.index(list_c[i])
	if len(list_b[idx]) < len(list_a[idx]):
		list_c[i] = list_b[idx]
print(' '.join(list_c))


(n, m) = map(int, input().split())
a = []
for i in range(m):
	a.append(list(map(str, input().split())))
b = list(map(str, input().split()))
ans = []
for i in b:
	for j in range(len(a)):
		if a[j][0] == i:
			if len(a[j][0]) <= len(a[j][1]):
				ans.append(a[j][0])
			else:
				ans.append(a[j][1])
print(*ans)


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(r, l) = input().split()
	dic[r] = l
for i in input().split():
	print(min(i, dic[i], key=len), end=' ')


(a, b) = input().split()
di = {}
for i in range(int(b)):
	s = input().split()
	i = s[0]
	if len(s[0]) <= len(s[1]):
		j = s[0]
	else:
		j = s[1]
	di.update({i: j})
st = input().split()
for i in st:
	print(di[i], end=' ')


(n, m) = [int(i) for i in input().split()]
l = []
a = []
for i in range(m):
	(g, h) = [str(i) for i in input().split()]
	l.append(g)
	a.append(h)
s = str(input())
s = s.split(' ')
z = []
for i in range(0, len(s)):
	d = s[i]
	if d in l:
		f = l.index(d)
		if len(l[f]) > len(a[f]):
			z.append(a[f])
		elif len(l[f]) < len(a[f]):
			z.append(l[f])
		else:
			z.append(l[f])
	elif d in a:
		f = l.index(d)
		if len(l[f]) > len(a[f]):
			z.append(a[f])
		elif len(l[f]) < len(a[f]):
			z.append(l[f])
		else:
			z.append(l[f])
print(*z)


def main():
	lst = {}
	(n, m) = list(map(int, input().split()))
	for i in range(m):
		(a, b) = list(input().split(' '))
		lst[a] = b
	sentence = list(input().split(' '))
	for i in range(n):
		if sentence[i] in lst:
			if len(sentence[i]) > len(lst[sentence[i]]):
				sentence[i] = lst[sentence[i]]
	print(' '.join(map(str, sentence)))
t = 1
while t != 0:
	main()
	t -= 1


(n, m) = [int(x) for x in input().split()]
dic = {}
for i in range(m):
	(fir, sec) = input().split()
	if len(fir) > len(sec):
		dic[fir] = sec
li = input().split()
for i in range(len(li)):
	if li[i] in dic:
		li[i] = dic[li[i]]
print(' '.join(li))


(n, m) = list(map(int, input().split()))
d_1 = []
d_2 = []
for i in range(m):
	(x, y) = list(map(str, input().split()))
	d_1.append(x)
	d_2.append(y)
l = [str(x) for x in input().split()]
for i in range(n):
	if len(d_2[d_1.index(l[i])]) < len(l[i]):
		l[i] = d_2[d_1.index(l[i])]
print(''.join([str(l[i]) + ' ' for i in range(n)]))


(n, m) = map(int, input().split())
dic = {}
r = ''
for i in range(m):
	(s1, s2) = map(str, input().split())
	dic.update({s1: s2})
s = input().split()
for i in range(len(s)):
	if len(s[i]) <= len(dic[s[i]]):
		r += s[i]
	else:
		r += dic[s[i]]
	if i < len(s) - 1:
		r += ' '
print(r)


dict = {}
(n, m) = [int(i) for i in input().split()]
for _ in range(m):
	test = [i for i in input().split()]
	if len(test[0]) <= len(test[1]):
		dict[test[1]] = test[0]
	else:
		dict[test[0]] = test[1]
res = ''
for e in input().split():
	if e in dict:
		res += dict[e]
	else:
		res += e
	res += ' '
print(res)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(x, y) = input().split()
	if len(x) < len(y):
		d[x] = [y, 1]
		d[y] = [x, 0]
	elif len(x) == len(y):
		d[x] = [y, 2]
		d[y] = [x, 2]
	else:
		d[x] = [y, 0]
		d[y] = [x, 1]
s = input().split()
for i in s:
	x = d[i]
	if x[1] == 1 or x[1] == 2:
		print(i, end=' ')
	else:
		print(x[0], end=' ')


(n, m) = map(int, input().split())
l = []
a = []
o = ''
for _ in range(m):
	(l1, l2) = input().split()
	if len(l1) <= len(l2):
		p = l1
	else:
		p = l2
	l.append(l1)
	a.append(p)
me = list(input().split())
for i in me:
	q = l.index(i)
	o += a[q] + ' '
print(o)


import sys
import math
import bisect
import itertools
import random
import re

def main():
	(n, m) = map(int, input().split())
	d = dict()
	for i in range(m):
		(s, t) = input().split()
		d[s] = t
	B = []
	for s in input().split():
		t = d[s]
		if len(s) <= len(t):
			B.append(s)
		else:
			B.append(t)
	print(' '.join(B))
main()


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(s1, s2) = input().split()
	if len(s1) <= len(s2):
		d[s2] = s1
		d[s1] = s1
	else:
		d[s1] = s2
		d[s2] = s2
s = input().split()
for i in range(n):
	temp = d[s[i]]
	s[i] = temp
print(' '.join(s))


(n, m) = map(int, input().split())
l1 = []
l2 = []
for _ in range(m):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
notes = list(map(str, input().split()))
ans = []
for w in notes:
	if w in l1:
		id = l1.index(w)
		if len(l1[id]) == len(l2[id]):
			ans.append(l1[id])
		elif len(l1[id]) < len(l2[id]):
			ans.append(l1[id])
		else:
			ans.append(l2[id])
	elif w in l2:
		id = l2.index(w)
		if len(l1[id]) == len(l2[id]):
			ans.append(l1[id])
		elif len(l1[id]) < len(l2[id]):
			ans.append(l1[id])
		else:
			ans.append(l2[id])
print(*ans)


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	(p, o) = map(str, input().split())
	if len(p) > len(o):
		a[p] = o
	else:
		a[p] = p
(s, r) = (input().split(' '), '')
for i in s:
	r += a[i] + ' '
print(r)


dict = {}
(n, m) = map(int, input().split())
for i in range(m):
	(x, y) = input().split()
	dict[x] = y
print(*[dict[i] if len(i) > len(dict[i]) else i for i in input().split()])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
l1 = []
l2 = []
for i in range(m):
	ll = input().split()
	l1.append(ll[0])
	l2.append(ll[1])
lec = input().split()
note = ''
for i in range(n):
	if len(l1[l1.index(lec[i])]) > len(l2[l1.index(lec[i])]):
		note += l2[l1.index(lec[i])] + ' '
	else:
		note += l1[l1.index(lec[i])] + ' '
print(note)


(n, m) = map(int, input().split())
words = []
for i in range(m):
	words.append(list(input().split()))
s = list(input().split())
for i in s:
	for j in range(m):
		if i in words[j]:
			if len(words[j][0]) > len(words[j][1]):
				print(words[j][1], end=' ')
			else:
				print(words[j][0], end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	l = list(map(str, input().split()))
	d[l[0]] = l[1]
li = list(map(str, input().split()))
for i in range(n):
	if len(li[i]) <= len(d[li[i]]):
		print(li[i], end=' ')
	else:
		print(d[li[i]], end=' ')


import itertools as ittls
from collections import Counter
import string

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
(N, M) = inputarray()
A2B = {}
for i in range(M):
	(s, v) = input().split()
	A2B[s] = v
print(' '.join(map(lambda x: x if len(x) <= len(A2B[x]) else A2B[x], input().split())))


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	(p, q) = input().split()
	a[p] = q
s = list(input().split())
for i in range(n):
	if len(s[i]) > len(a[s[i]]):
		s[i] = a[s[i]]
print(' '.join(s))


(n, m) = (int(x) for x in input().split())
d = {}
for _ in range(m):
	(s1, s2) = (s for s in input().split())
	d[s1] = s2
ans = ''
for s in input().split():
	if len(s) <= len(d[s]):
		ans += s
	else:
		ans += d[s]
	ans += ' '
print(ans)


(n, m) = [int(x) for x in input().split()]
map1 = {}
map2 = {}
for i in range(m):
	(s1, s2) = [x for x in input().split()]
	map1[s1] = s2
	map1[s2] = ''
	map2[s2] = s1
	map2[s1] = ''
l = [x for x in input().split()]
ans = []
for i in l:
	s1 = map1[i]
	s2 = map2[i]
	if s1 == '':
		a = len(s2)
		b = len(i)
		if a <= b:
			ans.append(s2)
		else:
			ans.append(i)
	elif s2 == '':
		a = len(i)
		b = len(s1)
		if a <= b:
			ans.append(i)
		else:
			ans.append(s1)
for i in ans:
	print(i, end=' ')


from math import ceil, sqrt, floor
import sys
(n, m) = map(int, input().split())
mots = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		mots[a] = a
	else:
		mots[a] = b
for mot in input().split():
	print(mots[mot], end=' ')


(n, m) = map(int, input().split())
a = list()
b = list()
ans = list()
for i in range(m):
	(t1, t2) = input().split()
	a.append(t1)
	b.append(t2)
for word in input().split():
	index = [i for (i, string) in enumerate(a) if string == word]
	ans.append(a[index[-1]] if len(a[index[-1]]) <= len(b[index[-1]]) else b[index[-1]])
print(*ans)


(x, y) = map(int, input().split())
d = dict()
for __ in range(y):
	(a, b) = input().split()
	d[a] = b
a = list(input().split())
for i in a:
	if len(i) > len(d[i]):
		print(d[i], end=' ')
	else:
		print(i, end=' ')


l1 = {}
l2 = {}
(n, m) = [int(x) for x in input().split()]
for _ in range(m):
	(w1, w2) = input().split()
	l1[w1] = w2
	l2[w2] = w1
msg = input().split()
for i in range(len(msg)):
	lan1 = ''
	lan2 = ''
	if msg[i] in l1:
		lan1 = msg[i]
		lan2 = l1[lan1]
	else:
		lan2 = msg[i]
		lan1 = l2[lan2]
	if len(lan1) <= len(lan2):
		print(lan1, end='')
	else:
		print(lan2, end='')
	if i < len(msg) - 1:
		print(' ', end='')


(n, m) = [int(n1) for n1 in input().split()]
a = []
b = []
solu = []
for i in range(m):
	(a1, b1) = [str(n1) for n1 in input().split()]
	a.append(a1)
	b.append(b1)
	if len(a1) > len(b1):
		solu.append(b1)
	else:
		solu.append(a1)
c1 = [str(n1) for n1 in input().split()]
for i in range(n):
	if i != n - 1:
		print(solu[a.index(c1[i])], end=' ')
	else:
		print(solu[a.index(c1[i])])


(n, m) = map(int, input().split())
x = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	if min(len(a), len(b)) == len(a):
		x.update({b: a})
	elif len(a) == len(b):
		x.update({b: a})
	else:
		x.update({a: b})
g = input().split()
for i in range(len(g)):
	if g[i] not in x.values():
		g[i] = x[g[i]]
print(' '.join(g))


(n, m) = map(int, input().split())
val = {}
for i in range(m):
	tmp = list(input().split())
	a = tmp[0]
	b = tmp[1]
	if len(a) <= len(b):
		val[a] = a
	else:
		val[a] = b
lecture = list(input().split())
ans = ''
for x in lecture:
	ans += val[x] + ' '
print(ans)


(n, m) = map(int, input().split())
(a, b) = ([], [])
for _ in range(m):
	tmp = input().split()
	a.append(tmp[0])
	b.append(tmp[1])
lecture = list(input().split())
for word in lecture:
	if word in a:
		tmp = a.index(word)
	else:
		tmp = b.index(word)
	if len(a[tmp]) > len(b[tmp]):
		print(b[tmp], end=' ')
	else:
		print(a[tmp], end=' ')


(n, m) = map(int, input().split())
a = []
b = {}
for i in range(m):
	f = input().split()
	a.append(f)
	b[f[0]] = f[1]
s = input().split()
for i in s:
	if len(i) > len(b[i]):
		print(b[i], end=' ')
	else:
		print(i, end=' ')


(N, M) = map(int, input().split())
ma = {}
for i in range(M):
	(a, b) = input().split()
	if len(a) <= len(b):
		ma[a] = a
	else:
		ma[a] = b
ans = [ma[x] for x in input().split()]
print(' '.join(ans))


(n, m) = [int(i) for i in input().split()]
a = []
b = []
r = []
for i in range(m):
	(x, y) = [j for j in input().split()]
	a.append(x)
	b.append(y)
p = [i for i in input().split()]
for j in range(n):
	if p[j] in a:
		c = a.index(p[j])
	else:
		c = b.index(p[j])
	if len(b[c]) < len(a[c]):
		r.append(b[c])
	else:
		r.append(a[c])
for k in range(len(r)):
	print(r[k], end=' ')


(n, m) = list(map(int, input().split(' ')))
a = dict()
b = dict()
for i in range(m):
	tmp_words = input()
	(tmp_a, tmp_b) = tmp_words.split(' ')
	a[tmp_a] = tmp_b
	b[tmp_b] = tmp_a
result = ''
for word in input().split(' '):
	if word in a:
		result += len(word) <= len(a[word]) and word or a[word]
	else:
		result += len(word) < len(b[word]) and word or b[word]
	result += ' '
print(result)


dict = {}
(x, y) = [int(a) for a in input().split()]
for i in range(0, y):
	(n, m) = input().split()
	dict[n] = m
s = input().split()
ar = []
g = ''
for j in s:
	if len(j) > len(dict[j]):
		ar.append(dict[j])
	else:
		ar.append(j)
print(*ar)


(n, m) = [int(x) for x in input().split()]
k = {}
for i in range(m):
	(s1, s2) = input().split(' ')
	k.update({s1: s2})
s = input().split()
ans = ''
for wrd in s:
	if len(wrd) <= len(k[wrd]):
		ans = ans + wrd + ' '
	else:
		ans = ans + k[wrd] + ' '
print(ans)


(n, m) = map(int, input().split())
mapping = dict()
for x in range(m):
	(a, b) = input().split()
	mapping[a] = b
word = list(input().split())
for x in word:
	if len(x) <= len(mapping[x]):
		print(x, end=' ')
	else:
		print(mapping[x], end=' ')


(n, m) = list(map(int, input().split()))
word = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		word[a] = a
	else:
		word[a] = b
res = ''
lecture = input().split()
for i in lecture:
	res += word[i] + ' '
print(res)


def findString(word):
	for i in range(m):
		if word == a[i]:
			if len(a[i]) <= len(b[i]):
				return a[i]
			else:
				return b[i]
(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(s1, s2) = input().split()
	a.append(s1)
	b.append(s2)
s = list(input().split())
for i in range(n):
	s[i] = findString(s[i])
print(*s)


dic = {}
(n, m) = [int(x) for x in input().split()]
for i in range(0, m):
	(a, b) = input().split()
	if len(a) > len(b):
		dic[a] = b
	else:
		dic[a] = a
lecture = input().split()
for word in lecture:
	print(dic[word], end=' ')


(n, m) = map(int, input().split())
dic = dict([])
for i in range(m):
	a = input().split()
	(x, y) = (a[0], a[1])
	if len(y) < len(x):
		dic[x] = y
	else:
		dic[y] = x
t = input().split()
for i in t:
	if i in dic.keys():
		print(dic[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = list(map(int, input().split()))
a = {}
for i in range(m):
	(b, c) = list(input().split())
	a[b] = c
d = input()
d = d.split()
for i in d:
	(e, f) = (len(i), len(a[i]))
	if e < f:
		print(i, end=' ')
	if e > f:
		print(a[i], end=' ')
	if e == f:
		print(i, end=' ')


(n, m) = map(int, input().split())
my_dict = {}
for i in range(m):
	(a, b) = input().split()
	my_dict[a] = b
inp = input().split()
for i in range(n):
	if len(inp[i]) <= len(my_dict[inp[i]]):
		print(inp[i], end=' ')
	else:
		print(my_dict[inp[i]], end=' ')


(n, m) = map(int, input().split())
l = []
k = []
for i in range(m):
	(a, b) = map(str, input().split())
	if len(b) < len(a):
		l.append(b)
		k.append(a)
	else:
		l.append(a)
		k.append(b)
s = list(map(str, input().split()))
for i in s:
	if i in l:
		print(i, end=' ')
	else:
		print(l[k.index(i)], end=' ')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
l = list(input().split())
l1 = []
for i in l:
	if i in a:
		temp = a.index(i)
		if len(b[temp]) < len(i):
			l1.append(b[temp])
		else:
			l1.append(i)
	elif i in b:
		temp = b.index(i)
		if len(a[temp]) < len(i):
			l1.append(a[temp])
		else:
			l1.append(i)
for i in l1:
	print(i, end=' ')


(n, m) = list(map(int, input().split()))
d = {}
for i in range(m):
	(k, v) = list(input().split())
	d[k] = v
for i in input().split():
	if len(i) == len(d[i]):
		print(i, end=' ')
	elif len(i) < len(d[i]):
		print(i, end=' ')
	else:
		print(d[i], end=' ')


D = {}
lt = list(input().split())
(n, m) = (int(lt[0]), int(lt[1]))
while m != 0:
	m -= 1
	lt = list(input().split())
	if len(lt[1]) < len(lt[0]):
		D[lt[0]] = lt[1]
	else:
		D[lt[0]] = lt[0]
s = list(input().split())
for i in s:
	print(D[i], end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(k, v) = input().split()
	d[k] = v

def translate(w):
	w2 = d[w]
	if len(w2) < len(w):
		return w2
	else:
		return w
print(' '.join(map(translate, input().split())))


dictx = {}
(a, b) = map(int, input().split(' '))
for i in range(b):
	(x, y) = map(str, input().split(' '))
	if len(y) < len(x):
		dictx[x] = y
		dictx[y] = y
	else:
		dictx[y] = x
		dictx[x] = x
god = list(map(str, input().split(' ')))
strx = [dictx[i] for i in god]
print(' '.join(strx))


string = input()
numbers = string.split(' ')
n = int(numbers[1])
dictionary = {}
for x in range(n):
	string = input()
	words = string.split(' ')
	dictionary[words[0]] = words[1]
string = input()
words = string.split(' ')
newwords = []
for x in words:
	a = x
	b = dictionary[x]
	if len(b) < len(a):
		newwords.append(b)
	else:
		newwords.append(a)
print(' '.join(newwords))


(n, m) = [int(x) for x in input().split()]
d = dict()
for i in range(0, m):
	(str1, str2) = input().split()
	d[str1] = str2
lecture = input().split()
for word in lecture:
	word2 = d[word]
	if len(word2) < len(word):
		print(word2, end=' ')
	else:
		print(word, end=' ')


(a, b) = map(int, input().split())
wordDict = {}
for i in range(b):
	(x, y) = input().split()
	wordDict[x] = y
	wordDict[y] = x
words = input().split()
for word in words:
	if len(wordDict[word]) < len(word):
		print(wordDict[word], end=' ')
	else:
		print(word, end=' ')


(n, m) = input().split()
n = int(n)
m = int(m)
dict = {}
l = []
ans = [0] * 3001
for i in range(m):
	l.append([0] * 2)
y = 0
for i in range(m):
	(k, p) = input().split()
	l[i][0] = k
	l[i][1] = p
	if len(k) > len(p):
		dict[l[i][0]] = y
		ans[y] = l[i][1]
	else:
		dict[l[i][0]] = y
		ans[y] = l[i][0]
	y += 1
a = input().split()
for i in a:
	ind = dict.get(i)
	print(ans[ind], end=' ')


(n, m) = map(int, input().split(' '))
di = {}
for i in range(m):
	(a, b) = map(str, input().split(' '))
	di[a] = b
li = list(map(str, input().split(' ', n)[:n]))
st = ''
for i in range(len(li)):
	if len(li[i]) <= len(di[li[i]]):
		st += li[i]
	else:
		st += di[li[i]]
	st += ' '
print(st)


(n, m) = input().split()
n = int(n)
m = int(m)
d = {}
c = []
for i in range(m):
	(a, b) = input().split()
	c.append(a)
	d[a] = b
s = list(map(str, input().rstrip().split()))
for x in s:
	if len(x) <= len(d[x]):
		print(x, end=' ')
	else:
		print(d[x], end=' ')


class languagedic(dict):

	def __missing__(self, key):
		return key
(m, n) = map(int, input().split())
dic = languagedic()
for i in range(n):
	(fir, sec) = input().split()
	if len(fir) <= len(sec):
		dic[sec] = fir
	else:
		dic[fir] = sec
lectures = list(input().split())
for i in lectures:
	print(dic[i], end=' ')


(n, m) = list(map(int, input().split(' ')))
a_b = {}
for i in range(m):
	(a, b) = input().split(' ')
	a_b[a] = b
lecture = input().split(' ')
output = ''
for word in lecture:
	if len(word) > len(a_b[word]):
		output += a_b[word] + ' '
	else:
		output += word + ' '
print(output.rstrip())


inp = list(map(int, input().split()))
(n, m) = (inp[0], inp[1])
d = {}
word = []
for i in range(m):
	str = list(input().split())
	d[str[0]] = str[1]
word = list(input().split())
for i in word:
	if i in d:
		if len(i) > len(d[i]):
			print(d[i], end=' ')
		else:
			print(i, end=' ')


(n, k) = map(int, input().split())
d = {}
l = []
for i in range(k):
	(w1, w2) = input().split()
	if len(w2) < len(w1):
		d[w1] = w2
		d[w2] = w2
	else:
		d[w1] = w1
		d[w2] = w1
s = list(input().split())
for j in s:
	print(d[j], ' ', end='')
print()


def get_notes(dict, lecture):
	result = list()
	for s in lecture:
		if len(dict[s]) >= len(s):
			result.append(s)
		else:
			result.append(dict[s])
	return ' '.join(result)
n_m = [int(i) for i in input().split()]
dict = dict()
for i in range(n_m[1]):
	ws = [i for i in input().split()]
	dict[ws[0]] = ws[1]
lecture = [i for i in input().split()]
print(get_notes(dict, lecture))


(n, m) = [int(x) for x in input().split()]
l1 = {}
l2 = {}
di = {}
for i in range(m):
	(a, b) = input().split()
	l1[a] = len(a)
	l2[b] = len(b)
	di[a] = b
lst = input().split()
ls = []
for i in range(len(lst)):
	num1 = l1[lst[i]]
	num2 = l2[di[lst[i]]]
	if num1 > num2:
		ls.append(di[lst[i]])
	else:
		ls.append(lst[i])
print(' '.join(ls))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		d[a] = b
	elif len(b) > len(a):
		d[b] = a
	else:
		d[a] = a
s = input().split()
for i in s:
	if i in d.keys():
		print(d[i], end=' ')
	else:
		print(i, end=' ')


def lecture(lang, sentence, n, m):
	output = []
	word_to_dict = {}
	for word in sentence:
		if word in word_to_dict.keys():
			row = word_to_dict[word]
		else:
			r = 0
			while r < m:
				if lang[r][0] == word:
					row = r
					word_to_dict[word] = r
				r += 1
		word1 = lang[row][0]
		word2 = lang[row][1]
		if len(word1) > len(word2):
			output.append(word2)
		else:
			output.append(word1)
	print(' '.join(output))
(n, m) = list(map(int, input().strip().split(' ')))
lang = [[None for y in range(2)] for x in range(m)]
for row in range(m):
	lang[row] = input().strip().split(' ')
sentence = input().strip().split(' ')
lecture(lang, sentence, n, m)


lang1 = []
lang2 = []
(n, m) = map(int, input().split())
for _ in range(m):
	(a, b) = map(str, input().split())
	lang1.append(a)
	lang2.append(b)
ans = []
inp = [x for x in input().split()]
for i in inp:
	if len(i) <= len(lang2[lang1.index(i)]):
		ans.append(i)
	else:
		ans.append(lang2[lang1.index(i)])
print(*ans)


(n, m) = tuple(map(int, input().split()))
d = {}
for _ in range(m):
	(s1, s2) = tuple(input().split())
	d[s1] = s2
message = list(input().split())
answer = []
for word in message:
	if len(d[word]) < len(word):
		answer.append(d[word])
	else:
		answer.append(word)
print(' '.join(answer))


(n, m) = map(int, input().split())
a = {}
b = {}
for i in range(m):
	(x, y) = input().split()
	a[x] = y
	b[y] = x
S = input().split()
an = []
for s in S:
	if s in a and len(s) <= len(a[s]) or (s in b and len(s) < len(b[s])):
		an += [s]
	elif s in a:
		an += [a[s]]
	else:
		an += [b[s]]
print(' '.join(an))


(n, m) = input().split()
m = int(m)
lang = dict()
for i in range(m):
	(l1, l2) = input().split()
	lang[l1] = l1 if len(l1) <= len(l2) else l2
lecture = input().split()
notes = ''
for word in lecture:
	notes += lang[word]
	notes += ' '
print(notes)


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(a, b) = [i for i in input().split()]
	d[a] = [a, b]
for w in input().split():
	tmp = d[w]
	if len(tmp[0]) <= len(tmp[1]):
		print(tmp[0], end=' ')
	else:
		print(tmp[1], end=' ')


(n, m) = map(int, input().strip().split())
l = {}
for i in range(m):
	(s1, s2) = input().split()
	if len(s2) < len(s1):
		l[s1] = s2
		l[s2] = s2
	else:
		l[s1] = s1
		l[s2] = s1
for s in input().split():
	print(l[s], ' ', sep='', end='')
print()


(m, n) = map(int, str.split(input()))
kword = {}
for k in range(n):
	(i1, i2) = str.split(input())
	if len(i1) == len(i2):
		kword[i1] = i1
	elif len(i1) < len(i2):
		kword[i1] = i1
	else:
		kword[i1] = i2
lst = str.split(input())
for x in lst:
	print(kword[x], end=' ')


(n, m) = map(int, input().split())
ls = {}
while m:
	(a, b) = input().split()
	ls[a] = b if len(a) > len(b) else a
	m -= 1
c = list(input().split())
for word in c:
	print(ls[word], end=' ')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, m) = L()
A = [input().split() for i in range(m)]
d = {}
for i in range(m):
	d[A[i][0]] = [A[i][1], 1]
	d[A[i][1]] = [A[i][0], 2]
ans = []
s = input().split()
for i in range(n):
	x = d[s[i]][0]
	if len(x) < len(s[i]):
		ans.append(x)
	elif len(s[i]) < len(x):
		ans.append(s[i])
	elif d[s[i]][1] == 1:
		ans.append(s[i])
	else:
		ans.append(x)
print(' '.join(ans))
endtime = time.time()


(N, M) = map(int, input().split())
hashTable = {}
for _ in range(M):
	(string1, string2) = map(str, input().split())
	if len(string1) > len(string2):
		hashTable[string1] = string2
	else:
		hashTable[string1] = string1
lecture = list(map(str, input().split()))
res = ''
for i in range(N):
	res += hashTable[lecture[i]] + ' '
print(res)


(n, m) = [int(x) for x in input().split()]
zidian = {}
for i in range(m):
	(yi, er) = [x for x in input().split()]
	if len(yi) > len(er):
		zidian[yi] = er
	else:
		zidian[yi] = yi
s = ''
for x in input().split():
	s += zidian[x] + ' '
print(s)


(n, m) = input().split()
d = {}
for i in range(int(m)):
	(r, k) = input().split()
	v = min((r, k), key=len)
	d[r] = v
print(*[d[l] for l in input().split()])


(n, k) = map(int, input().split())
d = {}
for i in range(k):
	lis = list(input().split())
	d.update({lis[0]: lis[1]})
lis = list(input().split())
lis2 = []
for i in range(n):
	if len(lis[i]) <= len(d[lis[i]]):
		lis2.append(lis[i])
	else:
		lis2.append(d[lis[i]])
res = ' '.join(lis2)
print(res)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	la = len(a)
	lb = len(b)
	if la <= lb:
		d.update({a: a})
	else:
		d.update({a: b})
s = input()
ls = s.split()
na = []
for i in ls:
	print(d[i], end=' ')
print()


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	L = input().split()
	d[L[0]] = L[1]
s = input().split()
for i in range(n):
	if len(s[i]) > len(d[s[i]]):
		s[i] = d[s[i]]
print(*s, sep=' ')


(wordcount, linecount) = input().split()
words = {}
wordCnt = int(wordcount)
lineCnt = int(linecount)
for i in range(0, lineCnt):
	(word1, word2) = input().split()
	words[word1] = word2
lecture = input().split()
result = ''
for word in lecture:
	if len(words[word]) < len(word):
		result += words[word] + ' '
	else:
		result += word + ' '
print(result)


(n, k) = input().split(' ')
d = {}
for i in range(int(k)):
	(l1, l2) = input().split(' ')
	d[l1] = l2
lect = input().split()
for c in lect:
	cur_res = c
	if len(c) > len(d[c]):
		cur_res = d[c]
	print(cur_res, end=' ')


(n, m) = list(map(int, input().split()))
d = {}
for i in range(m):
	a = input().split()
	if len(a[0]) > len(a[1]):
		d[a[0]] = a[1]
	else:
		d[a[0]] = a[0]
n1 = input().split()
for i in n1:
	print(d[i], end=' ')
print()


(n, m) = map(int, input().split())
vocab = dict()
mask = dict()
for _ in range(m):
	(l1, l2) = input().split()
	vocab[l1] = l2
	if len(l1) > len(l2):
		mask[l1] = 0
	else:
		mask[l1] = 1
lecture = list(input().split())
out = ''
for v in lecture:
	if mask[v] == 0:
		out += vocab[v]
	else:
		out += v
	out += ' '
print(out)


(a, b) = map(int, input().split())
l = []
[l.append(input().split()) for j in range(b)]
for i in l:
	if len(i[0]) > len(i[1]):
		(i[0], i[1]) = (i[1], i[0])
for i in input().split():
	[print(j[0], end=' ') for j in l if i in j]


l = [int(x) for x in input().split()]
n = l[0]
m = l[1]
dic = {}
for i in range(0, m):
	lis = [x for x in input().split()]
	if len(lis[1]) < len(lis[0]):
		dic[lis[0]] = lis[1]
		dic[lis[1]] = lis[1]
	else:
		dic[lis[0]] = lis[0]
		dic[lis[1]] = lis[0]
lis1 = [x for x in input().split()]
for i in lis1:
	print(dic[i], end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	(a1, b1) = (len(a), len(b))
	if a1 <= b1:
		d[a] = a
	else:
		d[a] = b
l = list(map(str, input().split(' ')))
for i in l:
	print(d[i], end=' ')


words = dict()
(n, m) = [int(x) for x in input().split()]
for i in range(0, m):
	(s, s1) = input().split()
	words[s] = s1
s = input().split()
s1 = ''
for x in s:
	if len(words[x]) < len(x):
		s1 += words[x] + ' '
	else:
		s1 += x + ' '
print(s1[:len(s1) - 1])


def main():
	(n, m) = map(int, input().split())
	d = {}
	for _ in range(m):
		(a, b) = input().split()
		d[a] = d[b] = b if len(a) > len(b) else a
	print(' '.join([d[_] for _ in input().split()]))

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
s = {}
for i in range(k):
	z = list(input().split())
	s.setdefault(z[0], z[1])
lec = list(input().split())
for i in lec:
	k = s.get(i)
	if len(i) <= len(k):
		print(i, end=' ')
	else:
		print(k, end=' ')


(n, k) = [int(x) for x in input().split()]
d = {}
for i in range(k):
	(first, second) = input().split()
	d[first] = first if len(first) <= len(second) else second
first = True
for word in input().split():
	if not first:
		print(' ', end='')
	print(d[word], end='')
	first = False


(n, m) = map(int, input().split())
d = {}
ans = ''
for i in range(0, m):
	(s1, s2) = input().split()
	d[s1] = s2
s = input().split()
for k in s:
	if len(k) <= len(d[k]):
		ans = ans + k + ' '
	else:
		ans = ans + d[k] + ' '
print(ans)


(a, b) = map(int, input().split())
(v, c, z) = ([], [], [])
for i in range(b):
	(n, m) = input().split()
	v.append(n)
	c.append(m)
n = list(input().split())
for i in n:
	w = v.index(i)
	if len(v[w]) <= len(c[w]):
		z.append(v[w])
	else:
		z.append(c[w])
print(' '.join(z))


(n, m) = list(map(int, input().split()))
dict = {}
for i in range(m):
	(w1, w2) = list(input().split())
	dict[w1] = [w2, len(w1), len(w2)]
sen = list(input().split())
for i in sen:
	temp = dict[i]
	if temp[1] <= temp[2]:
		print(i, end=' ')
	else:
		print(temp[0], end=' ')


(a, b) = map(int, input().split())
d = {}
for _ in range(b):
	(w1, w2) = [x for x in input().split()]
	d[w1] = w2
l = [x for x in input().split()]
for i in l:
	if len(i) <= len(d[i]):
		print(i, end=' ')
	else:
		print(d[i], end=' ')


m: int = int(input().split()[1])
d: str = dict([])
for _ in range(m):
	s = input()
	w = s.split()
	if len(w[0]) <= len(w[1]):
		d[w[0]] = w[0]
		d[w[1]] = w[0]
	else:
		d[w[0]] = w[1]
		d[w[1]] = w[1]
s = input().split()
print(' '.join([d[w] for w in s]))


(n, m) = map(int, input().split())
mydict = {}
for i in range(0, m):
	(a, b) = input().split()
	mydict[a] = [b, len(a), len(b)]
arr = list(input().split())
ans = []
for i in arr:
	if mydict[i][1] <= mydict[i][2]:
		ans.append(i)
	else:
		ans.append(mydict[i][0])
for i in ans:
	print(i, end=' ')


(n, m) = map(int, input().split())
t = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		t[a] = b
p = input().split()
for (i, a) in enumerate(p):
	if a in t:
		p[i] = t[a]
print(' '.join(p))


def inlt():
	return list(map(str, input().split()))

def invr():
	return list(map(int, input().split()))
nm = invr()
n = nm[0]
m = nm[1]
a = []
b = []
for i in range(m):
	pair = inlt()
	a.append(pair[0])
	b.append(pair[1])
lect = inlt()
i = 0
while i < len(lect):
	w = lect[i]
	if w in a:
		ind = a.index(w)
		ib = b[ind]
		lect[i] = ib if len(ib) < len(w) else w
	i += 1
print(' '.join(lect))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
t = input().split()
a = []
for i in t:
	(lk, lv) = (0, 0)
	lk = len(i)
	lv = len(d[i])
	if lk < lv or lk == lv:
		a.append(i)
	else:
		a.append(d[i])
for x in a:
	print(x, end=' ')
print()


import sys

def main():
	(n, m) = tuple([int(x) for x in input().split()])
	trans = {}
	for i in range(m):
		line = input().split()
		if len(line[1]) < len(line[0]):
			trans[line[0]] = line[1]
		else:
			trans[line[0]] = line[0]
	lec = input().split()
	for i in range(len(lec)):
		print(trans[lec[i]], end='')
		if i + 1 != len(lec):
			print('', end=' ')
	print()
main()


(n, m) = [int(x) for x in input().split()]
dict = {}
for i in range(m):
	arr = [x for x in input().split()]
	dict[arr[0]] = arr[1]
s = list(input().split())
ans = ''
for i in range(n):
	if len(s[i]) <= len(dict[s[i]]):
		ans += s[i] + ' '
	else:
		ans += dict[s[i]] + ' '
print(ans)


i = input()
i = i.split()
i1 = int(i[1])
b = list()
p = dict()
for j in range(i1):
	k = input()
	i2 = k.split()
	if len(i2[0]) <= len(i2[1]):
		p[i2[0]] = i2[0]
	else:
		p[i2[0]] = i2[1]
w = input()
w = w.split()
for l in w:
	m1 = p[l]
	b.append(m1)
	b.append(' ')
print(''.join(b).strip())


(n, m) = [int(n) for n in input().split()]
letter = {}
for i in range(m):
	(a, b) = [str(a) for a in input().split()]
	if len(a) <= len(b):
		letter[a] = a
	else:
		letter[a] = b
sentence = [str(sentence) for sentence in input().split()]
for i in sentence:
	print(letter[i], end=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(w1, w2) = map(str, input().split())
	d[w1] = w2
l = list(map(str, input().split()))
for i in range(len(l)):
	if len(l[i]) > len(d[l[i]]):
		l[i] = d[l[i]]
print(*l)


(n, m) = input().split()
notes = []
words = list((input().split() for _ in range(int(m))))
lecture_words = input().split()
for i in range(len(lecture_words)):
	for j in range(len(words)):
		if str(words[j][0]) == str(lecture_words[i]):
			if len(words[j][0]) > len(words[j][1]):
				notes.append(words[j][1])
			else:
				notes.append(words[j][0])
print(*notes, sep=' ')


(n, m) = [int(x) for x in input().split()]
lexicon = {}
for i in range(m):
	(first, second) = [str(x) for x in input().split()]
	if len(first) <= len(second):
		lexicon[first] = first
	else:
		lexicon[first] = second
sentence = [lexicon[x] for x in input().split()]
print(' '.join(sentence))


(n, m) = map(int, input().split())
d = dict()
final = []
for i in range(m):
	(key, value) = input().split()
	d[key] = value
prof = input().split()
for i in range(n):
	s = d[prof[i]]
	if len(s) < len(prof[i]):
		final.append(s)
	else:
		final.append(prof[i])
print(' '.join(final))


from collections import *
from bisect import *
from math import *
from heapq import *
from fractions import *
import sys
input = sys.stdin.readline
t = 1

def r(a):
	return a * (a - 1) // 2
while t:
	t -= 1
	(n, m) = map(int, input().split())
	f = {}
	for i in range(m):
		a = input().split()
		if len(a[0]) == len(a[1]):
			continue
		if len(a[0]) > len(a[1]):
			f[a[0]] = a[1]
		else:
			f[a[1]] = a[0]
	b = input().split()
	for i in b:
		if i not in f:
			print(i, end=' ')
		else:
			print(f[i], end=' ')
	print()


x = list(map(int, input().split()))
n = x[0]
m = x[1]
p = []
q = []
t = []
for i in range(m):
	ab = list(map(str, input().split()))
	p.append(ab[0])
	q.append(ab[1])
c = list(map(str, input().split()))
for i in range(len(c)):
	r = p.index(c[i])
	s = min(p[r], q[r], key=len)
	t.append(s)
print(' '.join(t))


(n, m) = [int(x) for x in input().split()]
tr = {}
for i in range(m):
	(a, b) = input().split()
	if len(b) < len(a):
		tr[a] = b
s = input().split()
for i in range(len(s)):
	if s[i] in tr:
		s[i] = tr[s[i]]
print(' '.join(s))


(n, m) = map(int, input().split(' '))
(f, s) = ([], [])
for i in range(m):
	v = list(input().split(' '))
	f.append(v[0])
	s.append(v[1])
lect = list(input().split(' '))
for i in lect:
	if i in f:
		(l1, l2) = (len(f[f.index(i)]), len(s[f.index(i)]))
		if l2 < l1:
			print(s[f.index(i)], end=' ')
		else:
			print(i, end=' ')
	else:
		(l1, l2) = (len(i), len(f[s.index(i)]))
		if l2 < l1:
			print(f[s.index(i)], end=' ')
		else:
			print(i, end=' ')


(n, m) = map(int, input().split())
language = []
note = []
for i in range(m):
	(temp1, temp2) = map(str, input().split(' '))
	language.append(temp1)
	if len(temp1) <= len(temp2):
		note.append(temp1)
	else:
		note.append(temp2)
lecture = input().split(' ')
output = []
for x in lecture:
	pos = language.index(x)
	output.append(note[pos])
print(' '.join(output))


(n, m) = map(int, input().split())
arr = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	if len(a) > len(b):
		arr[a] = b
lect = input().split()
res = []
for i in lect:
	if i in arr:
		res.append(arr[i])
	else:
		res.append(i)
print(' '.join(res))


nums = input().split()
n = int(nums[0])
m = int(nums[1])
d = {}
for i in range(0, m):
	strs = input().split()
	if len(strs[0]) <= len(strs[1]):
		d[strs[0]] = strs[0]
	else:
		d[strs[0]] = strs[1]
text = input().split()
for word in text:
	print(d[word], end=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(x, y) = input().split()
	dic[x] = y
	dic[y] = x
ans = []
for i in input().split():
	x = i
	if len(dic[x]) < len(x):
		ans.append(dic[x])
	else:
		ans.append(x)
print(*ans)


(n, m) = map(int, input().split())
D = {}
E = {}
for i in range(m):
	(x, y) = input().split()
	D[x] = y
	E[y] = x
s = input()
ans = ''
for w in s.split():
	if w in D:
		if len(w) <= len(D[w]):
			ans += w
		else:
			ans += D[w]
	if w in E:
		if len(w) <= len(E[w]):
			ans += w
		else:
			ans += E[w]
	ans += ' '
print(ans)


(n, m) = map(int, input().split())
L = [str(input()).split(' ') for _ in range(m)]
M = str(input()).split(' ')
R = ['' for _ in range(m)]
B = ['' for _ in range(m)]
for i in range(m):
	a = len(L[i][0])
	b = len(L[i][1])
	if a <= b:
		R[i] = L[i][0]
		B[i] = L[i][1]
	else:
		R[i] = L[i][1]
		B[i] = L[i][0]
R = R + B
r = ''
for i in range(n):
	e = R.index(M[i])
	r += R[e % m] + ' '
print(r)


(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(m):
	(x, y) = input().split()
	d[x] = y
for string in input().split():
	if len(d[string]) < len(string):
		print(d[string], end=' ')
	else:
		print(string, end=' ')
print()


(n, m) = map(int, input().split())
first_lang = {}
second_lang = {}
for _ in range(m):
	words = input().split()
	first_lang[words[0]] = words[1]
	second_lang[words[1]] = words[0]
text = input().split()
for word in text:
	second = first_lang.get(word)
	if second and len(second) < len(word):
		print(second, end=' ')
		continue
	first = second_lang.get(word)
	if first and len(first) <= len(word):
		print(first, end=' ')
		continue
	print(word, end=' ')


(_, wordCount) = map(int, input().split())
words = {}
for line in range(wordCount):
	(first, second) = input().split()
	words[first] = second
result = []
sentence = input()
for word in sentence.split():
	differentLanguage = words[word]
	if len(differentLanguage) < len(word):
		result.append(differentLanguage)
	else:
		result.append(word)
print(' '.join(result))


(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * m
for i in range(m):
	(l, r) = input().split()
	a[i] = l
	b[i] = r
	if len(l) <= len(r):
		c[i] = l
	else:
		c[i] = r
s = list(input().split())
answer = ''
for i in range(n):
	if s[i] in a:
		x = a.index(s[i])
	else:
		x = b.index(s[i])
	answer += c[x]
	answer += ' '
tr = len(answer)
print(answer[0:tr - 1])


(n, m) = map(int, input().split())
x = [None] * m
for i in range(m):
	x[i] = [x for x in input().split()]
y = [x for x in input().split()]
for i in range(n):
	for j in range(m):
		if y[i] in x[j]:
			if len(x[j][0]) <= len(x[j][1]):
				y[i] = x[j][0]
			else:
				y[i] = x[j][1]
for i in range(n):
	print(y[i], end=' ')


(n, m) = map(int, input().split())
a = []
b = []
ans = []
for i in range(m):
	(u, v) = input().split(' ')
	a.append(u)
	b.append(v)
c = list(input().split())
for i in range(n):
	x = c[i]
	if x in a:
		ia = a.index(x)
		y = b[ia]
		xl = len(x)
		yl = len(y)
		if xl > yl:
			ans.append(y)
		elif xl == yl:
			ans.append(x)
		else:
			ans.append(x)
	else:
		ib = b.index(x)
		y = a[ib]
		xl = len(x)
		yl = len(y)
		if xl > yl:
			ans.append(y)
		elif xl == yl:
			ans.append(x)
		else:
			ans.append(x)
print(*ans)


(n, m) = map(int, input().split())
k = {}
for i in range(m):
	(a, b) = input().split()
	k[a] = b
r = input().split()
l = [r[j] if len(r[j]) <= len(k[r[j]]) else k[r[j]] for j in range(n)]
print(' '.join(l))


(n, m) = map(int, input().split())
(f, s) = ([], [])
for i in range(m):
	a = input().split()
	f.append(a[0])
	s.append(a[1])
Q = input().split()
ans = ''
for i in range(n):
	Ind = -1
	for j in range(m):
		if f[j] == Q[i]:
			Ind = j
			break
	W = f[Ind]
	if len(s[Ind]) < len(W):
		W = s[Ind]
	ans += W + ' '
print(ans)


(n, m) = map(int, input().split())
DC = {}
for i in range(m):
	(s, s1) = map(str, input().split())
	DC[s] = s1
	DC[s1] = s
A = list(map(str, input().split(' ')[:n]))
for i in A:
	if len(i) > len(DC[i]):
		print(DC[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = map(int, input().split())
from collections import defaultdict
d = defaultdict(str)
for i in range(m):
	(a, b) = map(str, input().split())
	d[a] = min(a, b, key=len)
	d[b] = min(a, b, key=len)
a = list(map(str, input().split()))
res = str()
for i in a:
	res += d[i]
	res += ' '
print(res)


(_, m) = map(int, input().split())
d = {i[0]: i[1] for i in (input().split() for _ in range(m))}
c = input().split()
for i in range(len(c)):
	if len(c[i]) > len(d[c[i]]):
		c[i] = d[c[i]]
print(*c)


(n, m) = map(int, input().split())
word_dict = dict()
for _ in range(m):
	(first, second) = input().split()
	if len(second) >= len(first):
		word_dict[first] = first
	else:
		word_dict[first] = second
lecture = input().split()
for word in lecture:
	print(word_dict[word], end=' ')
print()


(n, m) = map(int, input().split())
words = dict()
for i in range(m):
	(w1, w2) = map(str, input().split())
	w = w1
	if len(w2) < len(w1):
		w = w2
	words[w1] = w
	words[w2] = w
data = input().split()
for i in range(n):
	print(words[data[i]], end=' ')


(x, y) = input().split()
x = int(x)
y = int(y)
st1 = []
st2 = []
for i in range(y):
	(s1, s2) = input().split()
	st1.append(s1)
	st2.append(s2)
sr = input()
words = [str(w) for w in sr.split()]
for word in words:
	i = st1.index(word)
	if len(st1[i]) <= len(st2[i]):
		print(st1[i], end=' ')
	else:
		print(st2[i], end=' ')


(n, m) = map(int, input().split())
hash_map = {}
for i in range(m):
	(x, y) = input().split()
	hash_map[x] = y
notes = list(map(str, input().strip().split()))
for i in range(n):
	if len(str(notes[i])) <= len(hash_map[notes[i]]):
		continue
	else:
		notes[i] = hash_map[notes[i]]
for i in notes:
	print(i, end=' ')


(n, m) = map(int, input().split())
translation = {}
ans = ''
for _ in range(m):
	(first, second) = input().split()
	if len(first) <= len(second):
		translation[first] = first
		translation[second] = first
	else:
		translation[second] = second
		translation[first] = second
lecture = input().split(' ')
for j in lecture:
	ans += translation[j] + ' '
print(ans)


l = input().split()
a = int(l[0])
b = int(l[1])
dic = {}
for i in range(b):
	p = input().split()
	if len(p[0]) > len(p[1]):
		dic[p[0]] = p[1]
		dic[p[1]] = p[1]
	elif len(p[0]) <= len(p[1]):
		dic[p[1]] = p[0]
		dic[p[0]] = p[0]
r = input().split()
s = dic[r[0]]
for i in range(1, a):
	s = s + ' ' + dic[r[i]]
print(s)


(n, m) = map(int, input().split())
(a, b) = ([], [])
for i in range(m):
	(x, y) = map(str, input().split(' '))
	a.append(x)
	b.append(y)
l = list(map(str, input().split(' ')))
for i in range(n):
	if l[i] in a:
		ind = a.index(l[i])
		if len(a[ind]) <= len(b[ind]):
			print(a[ind], end=' ')
		else:
			print(b[ind], end=' ')
	else:
		ind = b.index(l[i])
		if len(a[ind]) <= len(b[ind]):
			print(a[ind], end=' ')
		else:
			print(b[ind], end=' ')


class Solution:

	def __init__(self):
		(self.n, self.m) = [int(x) for x in input().split()]
		(self.a, self.b) = ([], [])
		for _ in range(self.m):
			(a, b) = [x for x in input().split()]
			self.a.append(a)
			self.b.append(b)
		self.c = [x for x in input().split()]

	def solve_and_print(self):
		for c in self.c:
			for (a, b) in zip(self.a, self.b):
				if a == c:
					print(a if len(a) <= len(b) else b, end=' ')
Solution().solve_and_print()


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(s1, s2) = input().split()
	(dic[s1], dic[s2]) = (s2, s1)
s = input().split()
for i in range(len(s)):
	s[i] = min(s[i], dic[s[i]], key=len)
res = ' '.join(s)
print(res)


from itertools import *
from bisect import *

def main(n, m, a, b, s, ab):
	ans = []
	ab.sort()
	a = [x for (x, y) in ab]
	b = [y for (x, y) in ab]
	for i in range(n):
		j = bisect_left(a, s[i])
		if len(a[j]) <= len(b[j]):
			ans.append(a[j])
		else:
			ans.append(b[j])
	print(' '.join(ans))

def main_input(info=0):
	(n, m) = map(int, input().split())
	(a, b, l) = (list(range(m)), list(range(m)), list(range(n)))
	for i in range(m):
		(a[i], b[i]) = input().split()
	s = input().split()
	ab = []
	for i in range(m):
		ab.append((a[i], b[i]))
	main(n, m, a, b, s, ab)
main_input()


(n, m) = list(map(int, input().split()))
ch = {}
for x in range(m):
	(a, b) = input().split()
	if len(b) < len(a):
		ch[a] = b
c = input().split()
for y in range(len(c)):
	if c[y] in ch.keys():
		c[y] = ch[c[y]]
print(' '.join(c))


(n, m) = list(map(int, input().split()))
dict_ = dict()
for i in range(m):
	(st, st1) = list(input().split())
	dict_[st] = st if len(st) <= len(st1) else st1
list_ = list(input().split())
for i in list_:
	print(dict_[i], end=' ')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(l1, l2) = input().split()
	a.append(l1)
	b.append(l2)
c = list(input().split())
for j in c:
	k = a.index(j)
	len1 = len(a[k])
	len2 = len(b[k])
	if len2 < len1:
		print(b[k], end=' ')
	else:
		print(j, end=' ')


(n, m) = map(int, input().split())
l1 = set()
w2w = {}
for _ in range(m):
	(w1, w2) = input().split()
	w2w[w1] = w2
	w2w[w2] = w1
	l1.add(w1)
res = []
lecture = input().split()
for w in lecture:
	if w in l1:
		w2 = w2w[w]
		w1 = w
	else:
		w1 = w2w[w]
		w2 = w
	if len(w1) == len(w2):
		res.append(w1)
	else:
		res.append(w1 if len(w1) < len(w2) else w2)
output = ' '.join(res)
print(output)


(n, m) = map(int, input().split())
langMap = {}
for i in range(m):
	temp = input().split()
	if temp[0] not in langMap:
		langMap[temp[0]] = temp[1]
	if temp[1] not in langMap:
		langMap[temp[1]] = temp[0]
wri = input().split()
ans = []
for i in wri:
	if len(i) <= len(langMap[i]):
		ans.append(i)
	else:
		ans.append(langMap[i])
for i in ans:
	print(i, end=' ')


(N, M) = map(int, input().split())
L1 = []
L2 = []
for _ in range(M):
	(a, b) = map(str, input().split())
	L1.append(a)
	L2.append(b)
L = list(map(str, input().split()))
s = []
for i in L:
	n1 = L1.index(i)
	if len(L2[n1]) < len(L1[n1]):
		s.append(L2[n1])
	else:
		s.append(L1[n1])
print(*s)


dic = {}
for i in range(int(input().split()[1])):
	m = input().split()
	dic[m[0]] = m[len(m[0]) > len(m[1])]
for i in input().split():
	print(dic[i], end=' ')


(n, m) = map(int, input().split())
dic = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	try:
		if len(a) < len(b):
			dic[a] = a
			dic[b] = a
		elif len(b) < len(a):
			dic[a] = b
			dic[b] = b
		elif len(a) == len(b):
			dic[a] = a
			dic[b] = a
	except KeyError:
		pass
s = input().split()
f = ''
for i in s:
	f += dic[i] + ' '
print(f.strip())


(n, m) = map(int, input().split())
lag1 = []
lag2 = []
while m > 0:
	x = input().split(' ')
	lag1.append(x[0])
	lag2.append(x[1])
	m -= 1
text = input().split(' ')
ans = []
for i in range(len(text)):
	a = lag1.index(text[i])
	x = lag1[a]
	y = lag2[a]
	short = min(x, y, key=len)
	ans.append(short)
str1 = ' '
print(str1.join(ans))


g = input()
(n, m) = [int(x) for x in g.split()]
dic = {}
lis = []
for i in range(m):
	r = input()
	(r1, r2) = r.split()
	if len(r1) <= len(r2):
		dic[r1] = r1
		dic[r2] = r1
	else:
		dic[r1] = r2
		dic[r2] = r2
t = input()
for x in t.split():
	lis.append(x)
result = ''
for x in lis:
	result = result + dic[x] + ' '
print(result)


(n, m) = map(int, input().split())
w = {}
for i in range(m):
	(a, b) = input().split()
	w[a] = b
s = list(input().split())
ans = []
for j in s:
	if len(w[j]) < len(j):
		ans.append(w[j])
	else:
		ans.append(j)
print(*ans)


(n, m) = map(int, input().split())
corr = dict()
for i in range(m):
	(a, b) = input().split()
	corr[a] = b
lecture = input().split()
notes = []
for i in lecture:
	if len(i) <= len(corr[i]):
		notes.append(i)
	else:
		notes.append(corr[i])
print(' '.join(notes))


(n, m) = map(int, input().split())
b = []
for i in range(m):
	a = list(map(str, input().split()))
	a.sort(key=len)
	b.append(a[0])
	b.append(a[1])
c = list(map(str, input().split()))
for i in c:
	t = b.index(i)
	if t % 2 == 0:
		print(b[t], end=' ')
	else:
		print(b[t - 1], end=' ')


(n, m) = map(int, input().split())
q1 = []
q2 = []
for i in range(m):
	(a, b) = input().split()
	q1.append(a)
	q2.append(b)
k = input()
l = list(k.split())
for i in range(n):
	a = q1.index(l[i])
	if len(q1[a]) > len(q2[a]):
		print(q2[a], end=' ')
	else:
		print(q1[a], end=' ')


(n, m) = map(int, input().split())
dict1 = {}
for i in range(m):
	(s1, s2) = input().split()
	if len(s1) <= len(s2):
		dict1[s1] = 1
	else:
		dict1[s1] = s2
list1 = list(input().split())
for i in range(n):
	if dict1[list1[i]] != 1:
		print(dict1[list1[i]], end=' ')
	else:
		print(list1[i], end=' ')


n_m = list(map(int, input().split()))
m = n_m[1]
lec = ''
D = {}
Di = {}
for i in range(m):
	l = list(input().split())
	l_a = l[0]
	l_b = l[1]
	D[l_a] = l_b
	Di[l_b] = l_a
lec_in = list(input().split())
for j in range(len(lec_in)):
	word = lec_in[j]
	if word in D.keys():
		if len(word) <= len(D[word]):
			lec = lec + word + ' '
		else:
			lec = lec + D[word] + ' '
	elif len(word) < len(Di[word]):
		lec = lec + word + ' '
	else:
		lec = lec + Di[word] + ' '
print(lec.rstrip())


import sys
import math

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)
(n, m) = ninp()
d = {}
for i in range(m):
	(s1, s2) = input().split()
	len1 = len(s1)
	len2 = len(s2)
	if len1 <= len2:
		d[s1] = s1
	else:
		d[s1] = s2
s = input().split()
for i in s:
	print(d.get(i), end=' ')


try:
	(n, m) = list(map(int, input().split()))
	i = 0
	l = []
	s = []
	while i < m:
		(a, b) = list(map(str, input().split()))
		l.append(a)
		s.append(b)
		i += 1
	t = list(map(str, input().split()))
	c = ''
	for j in range(0, n):
		if t[j] in l:
			d = l.index(t[j])
			g = len(l[d])
			f = len(s[d])
			if g > f:
				c = c + s[d] + ' '
			else:
				c = c + l[d] + ' '
		if t[j] in s:
			d = l.index(t[j])
			g = len(l[d])
			f = len(s[d])
			if g > f:
				c = c + s[d] + ' '
			else:
				c = c + l[d] + ' '
	print(c[0:-1])
except:
	pass


(n, m) = input().split()
n = int(n)
m = int(m)
l1 = [''] * m
l2 = [''] * m
fs = [0] * m
for i in range(m):
	(s1, s2) = input().split()
	l1[i] = s1
	l2[i] = s2
ins = [i for i in input().split()]
for i in range(m):
	if len(l1[i]) <= len(l2[i]):
		fs[i] = 1
	else:
		fs[i] = 2
for j in range(n):
	for i in range(m):
		if ins[j] == l1[i]:
			break
	if fs[i] == 1:
		print(l1[i], end=' ')
	else:
		print(l2[i], end=' ')


inputz = input().split()
n = int(inputz[0])
m = int(inputz[1])
word = {}
for i in range(m):
	temp = input().split()
	if len(temp[0]) <= len(temp[1]):
		shorter = temp[0]
	else:
		shorter = temp[1]
	word[temp[0]] = shorter
inputz = input().split()
for i in inputz:
	print(word[i], end=' ')


def min(l):
	if l[0] <= l[1]:
		return 0
	return 1
(n, m) = [int(x) for x in input().split()]
a = []
b = []
for i in range(m):
	p = []
	p = [x for x in input().split()]
	l1 = len(p[0])
	l2 = len(p[1])
	if l1 <= l2:
		a.append(p[0])
		b.append(p[1])
	else:
		b.append(p[0])
		a.append(p[1])
str = []
str = [x for x in input().split()]
for x in str:
	try:
		p = a.index(x)
	except:
		p = -1
	if p == -1:
		p = b.index(x)
		print(a[p], end=' ')
	else:
		print(x, end=' ')


(n, m) = map(int, input().split())
lecture = {}
d = []
for i in range(m):
	(s1, s2) = map(str, input().split())
	lecture[s1] = s2
l = list(input().split())
for i in l:
	if len(lecture[i]) == len(i) or len(lecture[i]) > len(i):
		d.append(i)
	else:
		d.append(lecture[i])
for i in d:
	print(i, end=' ')


(n, m) = [int(i) for i in input('').split()]
dictionary = {}
for i in range(m):
	(a, b) = [i for i in input('').split()]
	dictionary[a] = b
lecture = input('')
words = lecture.split()
output = []
for word in words:
	if len(dictionary[word]) < len(word):
		output.append(dictionary[word])
	else:
		output.append(word)
print(' '.join(output))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
s = input().split()
for i in s:
	if len(i) < len(d[i]):
		print(i, end=' ')
	elif len(i) > len(d[i]):
		print(d[i], end=' ')
	else:
		for j in d:
			if d[j] == i or j == i:
				print(j, end=' ')
				break


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(s1, s2) = input().split()
	d[s1] = s2
s = list(input().split())
for i in s:
	if len(d[i]) < len(i):
		print(d[i], end=' ')
	else:
		print(i, end=' ')
print()


(n, m) = map(int, input().split())
d = dict()
while m:
	(a, b) = input().split()
	la = len(a)
	lb = len(b)
	if la <= lb:
		d[a] = a
	else:
		d[a] = b
	m -= 1
text = input().split()
ans = []
for i in text:
	ans.append(d[i])
print(' '.join(ans))


(a, b) = map(int, input().split())
slov = {}
for i in range(0, b):
	(c, d) = map(str, input().split())
	if len(c) < len(d) or len(c) == len(d):
		slov[c] = c
	else:
		slov[c] = d
mas = [str(i) for i in input().split()]
k = str()
for i in mas:
	k = k + slov[i] + ' '
print(k)


(n, m) = list(map(int, input().split()))
a = []
for i in range(m):
	a.append(list(input().split()))
b = list(input().split())
c = []
d = {}
for j in range(len(a)):
	if len(a[j][1]) < len(a[j][0]):
		d[a[j][0]] = a[j][1]
	else:
		d[a[j][0]] = a[j][0]
for i in b:
	c.append(d[i])
print(*c)


(n, m) = map(int, input().split())
d = {}
for i in range(0, m):
	(s1, s2) = input().split()
	if len(s1) > len(s2):
		d[s1] = s2
prof_lec = list(input().split())
result = []
for item in prof_lec:
	if item in d:
		result.append(d[item])
	else:
		result.append(item)
print(' '.join(result))


f = dict()
(a, b) = map(int, input().split())
for i in range(b):
	(c, d) = input().split()
	f[c] = d
for i in input().split():
	print(min(i, f[i], key=len), end=' ')


(n, k) = map(int, input().split())
res = {}
temp = []
for i in range(k):
	(r, s) = input().split()
	res[r] = s
lecture = input()
temp = lecture.split(' ')
for i in range(len(temp)):
	if len(temp[i]) <= len(res[temp[i]]):
		print(temp[i], end=' ')
	else:
		print(res[temp[i]], end=' ')


input1 = list(map(int, input().split()))
n = input1[0]
m = input1[1]
langMix = []
langAll = []
output = []
for i in range(m):
	langMix = input().split()
	langAll.append(langMix[0])
	langAll.append(langMix[1])
lecture1 = input().split()
dict1 = {}
for i in range(len(langAll)):
	if i % 2 == 0:
		dict1[langAll[i]] = langAll[i + 1]
output = []
for i in range(n):
	if len(lecture1[i]) > len(dict1[lecture1[i]]):
		output.append(dict1[lecture1[i]])
	else:
		output.append(lecture1[i])
print(' '.join(output))


(n, m) = (int(_) for _ in input().split(' '))
dictionary = {}
for _ in range(m):
	(a, b) = input().split(' ')
	dictionary[a] = b
output = []
for word in input().split():
	if len(word) <= len(dictionary[word]):
		output.append(word)
	else:
		output.append(dictionary[word])
print(' '.join(output))


from sys import stdin, stderr

def readInts():
	return map(int, stdin.readline().strip().split())

def print_err(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def solve(vs):
	return None

def run():
	(text_size, dict_size) = readInts()
	d = {}
	for _ in range(dict_size):
		(l1, l2) = input().strip().split()
		d[l1] = l2
	out = []
	for w1 in input().strip().split():
		w2 = d[w1]
		if len(w2) < len(w1):
			out.append(w2)
		else:
			out.append(w1)
	print(' '.join(out))
run()


(n, m) = map(int, input().split())
d = dict((input().split() for _ in range(m)))
t = list(input().split(' '))
s = ''
for i in range(len(t)):
	if len(t[i]) > len(d[t[i]]):
		s = s + d[t[i]] + ' '
	else:
		s = s + t[i] + ' '
print(s)


(n, m) = input().split(' ')
m = int(m)
n = int(n)
language_1 = []
language_2 = []
for _i in range(m):
	item = input().split(' ')
	language_1.append(item[0])
	language_2.append(item[1])
string = input().split(' ')
for i in range(n):
	index = -1
	if string[i] in language_1:
		index = language_1.index(string[i])
	elif string[i] in language_2:
		index = language_2.index(string[i])
	if index > -1:
		string[i] = language_1[index] if len(language_1[index]) <= len(language_2[index]) else language_2[index]
print(' '.join(string))


def run():
	import sys
	sys.stdin = open('/home/punit/Documents/Cpp Programs/input.txt', 'r')
	sys.stdout = open('/home/punit/Documents/Cpp Programs/output.txt', 'w')
	from math import ceil, sqrt, floor
(n, m) = map(int, input().split())
d = dict()
for _ in range(m):
	(a, b) = map(str, input().split())
	if len(a) > len(b):
		d[a] = b
		d[b] = b
	elif len(a) < len(b):
		d[a] = a
		d[b] = a
	else:
		d[a] = a
		d[b] = b
s = map(str, input().split())
for i in s:
	print(d[i], end=' ')


t = input().split()
n = int(t[0])
m = int(t[1])
a = []
b = {}
for i in range(m):
	t = input().split()
	t1 = t[0]
	t2 = t[1]
	if len(t1) > len(t2):
		a.append(t1)
		b[t1] = t2
	else:
		a.append(t2)
		b[t2] = t1
t = input().split()
for i in range(len(t)):
	if t[i] in a:
		t[i] = b[t[i]]
print(' '.join(t))


(n, m) = map(int, input().split())
x = {}
for i in range(m):
	(a, b) = input().split()
	if len(b) < len(a):
		x[a] = b
	else:
		x[a] = a
text = list(input().split())
for i in text:
	print(x[i], end=' ')


(n, m) = map(int, input().split())
first = dict()
second = dict()
for i in range(m):
	(s1, s2) = input().split()
	first[s1] = s2
	second[s2] = s1
lection = input().split()
for i in lection:
	if len(i) > len(first[i]):
		print(first[i], end=' ')
	else:
		print(i, end=' ')


from sys import stdin
(n, m) = list(map(int, stdin.readline().split()))
d = {}
for _ in range(m):
	(a, b) = stdin.readline().split()
	d[a] = b if len(b) < len(a) else a
s = stdin.readline().split()
res = []
for t in s:
	res.append(d[t])
print(' '.join(res))


(n, m) = map(int, input().split())
b = {}
for i in range(m):
	(k, l) = input().split()
	a = {len(k): k, len(l): l}
	if len(k) == len(l):
		b[k] = k
	else:
		b[k] = a[min(len(k), len(l))]
q = input().split()
m = ''
for r in q:
	m += '{} '.format(b[r])
print(m)


first = input().split()
n = int(first[0])
m = int(first[1])
data = {}
while m:
	m -= 1
	line = input().split()
	if len(line[0]) <= len(line[1]):
		data[line[0]] = line[0]
	else:
		data[line[0]] = line[1]
line = input().split()
for i in range(len(line)):
	print(data[line[i]])


[n, m] = list(map(int, input().split()))
d = {}
for i in range(m):
	[a, b] = input().split()
	la = len(a)
	lb = len(b)
	if la <= lb:
		d[a] = a
		d[b] = a
	else:
		d[a] = b
		d[b] = b
c = input().split()
os = ''
for word in c:
	os += d[word] + ' '
print(os.strip())


(x, y) = map(int, input().split())
t = []
d = {}
for i in range(y):
	a = input().split()
	d[a[0]] = a[1]
l = input().split()
for i in range(x):
	if len(l[i]) > len(d[l[i]]):
		print(d[l[i]], end=' ')
	elif len(l[i]) <= len(d[l[i]]):
		print(l[i], end=' ')


(a, b) = map(int, input().split())
l1 = []
l2 = []
l3 = []
l4 = []
ind = 0
for i in range(0, b):
	(s1, s2) = map(str, input().split(' '))
	l1.append(s1)
	l2.append(s2)
	if len(s1) <= len(s2):
		l3.append(s1)
	else:
		l3.append(s2)
l4 = list(map(str, input().split(' ')))
for i in range(0, a):
	ind = l1.index(l4[i])
	print(l3[ind], end=' ')


(a, b) = map(int, input().split())
lecture = []
l1 = []
l2 = []
while b > 0:
	(a, b1) = map(str, input().split())
	if len(a) > len(b1):
		lan = b1
	else:
		lan = a
	l1.append(a)
	l2.append(lan)
	b -= 1
d = dict(zip(l1, l2))
word = input().split()
str1 = ''
for i in word:
	lan = str(d[i])
	str1 += lan
	if word.index(i) < len(word) - 1:
		str1 += ' '
	else:
		pass
print(str1)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b if len(b) < len(a) else a
s = input().split()
ans = [d[i] for i in s]
print(*ans)


(n, m) = map(int, input().split())
lst = list()
mydict = dict()
for i in range(m):
	temp = input()
	words = temp.split()
	mydict[words[0]] = words[1]
s = input()
w = s.split(' ')
m = list()
for word in w:
	if len(mydict[word]) < len(word):
		m.append(mydict[word])
	else:
		m.append(word)
st = ''
for word in m:
	st = st + word + ' '
print(st)


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	m = input().split()
	a.append(m[0])
	b.append(m[1])
for i in input().split():
	c = a.index(i)
	if len(a[c]) <= len(b[c]):
		print(a[c], end=' ')
	else:
		print(b[c], end=' ')


(n, m) = map(int, input().split())
l = []
l1 = []
for i in range(m):
	t = list(map(str, input().split()))
	if len(t[0]) > len(t[1]):
		(t[0], t[1]) = (t[1], t[0])
	l.append(t)
	l1.append(t[0])
	l1.append(t[1])
l2 = list(map(str, input().split()))
for i in range(len(l2)):
	x = l2[i]
	ind = l1.index(x)
	ind = ind // 2
	l2[i] = l[ind][0]
for i in l2:
	print(i, end=' ')


import sys
import math
input = sys.stdin.readline

def int_array():
	return list(map(int, input().split()))

def str_array():
	return list(map(str, input().split()))
(n, k) = int_array()
words = []
for i in range(k):
	words += str_array()
sentence = str_array()
ans = ''
for i in sentence:
	no = words.index(i)
	if len(words[no]) > len(words[no + 1]):
		ans += words[no + 1] + ' '
	else:
		ans += words[no] + ' '
print(ans)


res = {}
(n, m) = map(int, input().split())
for i in range(m):
	(a, b) = input().split()
	if a not in res:
		res[a] = b
li = list(input().split())
for i in range(n):
	if len(res[li[i]]) < len(li[i]):
		li[i] = res[li[i]]
print(*li)


(n, m) = map(int, input().split())
a = dict()
for i in range(m):
	a.update({map(str, input().split())})
s = [str(i) for i in input().split()]
for i in range(n):
	if len(s[i]) > len(a[s[i]]):
		s[i] = a[s[i]]
b = ' '.join(s)
print(b)


(n, m) = [int(i) for i in input().split()]
D = {}
for i in range(m):
	(a, b) = [j.strip() for j in input().split()]
	D[a] = b
Note = [i.strip() for i in input().split()]
for i in Note:
	if len(i) > len(D[i]):
		print(D[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = []
r = []
out = []
short = []
for i in range(m):
	s = input().split(' ')
	l.append(s[0])
	r.append(s[1])
	if len(s[0]) <= len(s[1]):
		short.append(s[0])
	else:
		short.append(s[1])
s = input().split(' ')
for i in range(n):
	if s[i] in l:
		x = l.index(s[i])
		out.append(short[x])
print(' '.join(out))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(w1, w2) = input().split()
	l1 = len(w1)
	l2 = len(w2)
	if l1 <= l2:
		d[w1] = w1
		d[w2] = w1
	else:
		d[w1] = w2
		d[w2] = w2
a = []
for s in input().strip().split():
	a.append(d[s])
print(' '.join(a))


def language(arr, string):
	temp = {}
	for i in arr:
		if len(i[1]) < len(i[0]):
			temp[i[0]] = i[1]
	for i in range(len(string)):
		if string[i] in temp.keys():
			string[i] = temp[string[i]]
	print(*string)
	return ''
(a, b) = map(int, input().strip().split())
blanck = []
for i in range(b):
	(a, b) = input().strip().split()
	blanck.append([a, b])
lst = list(input().strip().split())
print(language(blanck, lst))


(n, m) = map(int, input().split())
final = {}
for _ in range(0, m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		final[a] = a
		final[b] = a
	else:
		final[a] = b
		final[b] = b
last = [i for i in input().split()]
for i in last:
	print(final[i], end=' ')


(n, m) = map(int, input().split())
from collections import defaultdict
d = defaultdict(lambda : '')
for _ in range(m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		d[a] = a
		d[b] = a
	else:
		d[a] = b
		d[b] = b
l = [str(x) for x in input().split()]
for i in l:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
a = []
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	a.append(y)
b = list(input().split())
for i in b:
	if i in a:
		ind = a.index(i)
		if ind % 2 == 0:
			if len(a[ind]) <= len(a[ind + 1]):
				print(a[ind], end=' ')
			else:
				print(a[ind + 1], end=' ')
		elif len(a[ind]) <= len(a[ind - 1]):
			print(a[ind], end=' ')
		else:
			print(a[ind - 1], end=' ')


(n, m) = map(int, input().split())
notes = {}
for i in range(m):
	(lan1, lan2) = map(str, input().split())
	if len(lan1) <= len(lan2):
		notes[lan1] = lan1
	else:
		notes[lan1] = lan2
lecture = input()
lecturenotes = list(lecture.split(' '))
for word in lecturenotes:
	print(notes[word], end=' ')


(n, m) = map(int, input().split())
dct = {}
for _ in range(m):
	(a, b) = input().split()
	dct[a] = b
s = input().split()
for i in s:
	print(min(i, dct[i], key=len), end=' ')


n = input().split()
dictionary = {}
for i in range(int(n[1])):
	l = input().split()
	if len(l[0]) > len(l[1]):
		dictionary[l[0]] = l[1]
	else:
		dictionary[l[0]] = l[0]
l = input().split()
for i in l:
	print(dictionary[i], end=' ')


a = input().strip().split()
notes = {}
for i in range(0, int(a[1])):
	b = input().strip().split()
	if len(b[0]) < len(b[1]):
		notes[b[0]] = b[0]
	elif len(b[0]) == len(b[1]):
		notes[b[0]] = b[0]
	else:
		notes[b[0]] = b[1]
lecture_notes = input().strip().split()
for i in lecture_notes:
	print(notes[i], end=' ')


(n, m) = map(int, input().split())
a = [0] * m
b = [0] * m
c = [0] * n
for i in range(m):
	(a[i], b[i]) = map(str, input().split())
c = list(map(str, input().split()))
for i in range(n):
	for j in range(m):
		if c[i] == a[j] or c[i] == b[j]:
			if len(a[j]) > len(b[j]):
				print(b[j], end=' ')
			else:
				print(a[j], end=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = map(str, input().split())
	la = len(a)
	lb = len(b)
	if la < lb:
		d[a] = a
	elif la > lb:
		d[a] = b
	else:
		d[a] = a
ls = list(map(str, input().split()))
s = ''
for j in range(n):
	if j == n - 1:
		s = s + d[ls[j]]
	else:
		s = s + d[ls[j]] + ' '
print(s)


str = input()
list = [int(n) for n in str.split()]
word1 = []
word2 = []
for i in range(list[1]):
	temp = [j for j in input().split()]
	word1.append(temp[0])
	word2.append(temp[1])
string = [j for j in input().split()]
output = ''
for i in range(len(string)):
	j = word1.index(string[i])
	if len(string[i]) > len(word2[j]):
		output = output + word2[j] + ' '
	else:
		output = output + string[i] + ' '
print(output)


(n, p) = map(int, input().split())
di = {}
for i in range(p):
	tmp = input().split()
	if len(tmp[0]) > len(tmp[1]):
		di[tmp[0]] = tmp[1]
	else:
		di[tmp[0]] = tmp[0]
tmp = input().split()
ans = ''
for i in tmp:
	ans = ans + ' ' + di[i]
print(ans[1:])


(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(m):
	(a, b) = [str(x) for x in input().split()]
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
s = [str(x) for x in input().split()]
for i in s:
	print(d[i], end=' ')
print()


(n, m) = [int(i) for i in input().split()]
dic = {}
for i in range(m):
	(a, b) = input().split()
	dic[a] = b
c = [s for s in input().split()]
for i in range(n):
	s = c[i]
	t = dic[s]
	if len(s) <= len(t):
		print(s, end=' ')
	else:
		print(t, end=' ')
print()


(n, m) = map(int, input().split())
hashmap = dict()
for i in range(m):
	(str1, str2) = input().split()
	if len(str1) <= len(str2):
		hashmap[str1] = str1
	else:
		hashmap[str1] = str2
temp = list(input().split())
res = ''
for i in range(n):
	res += hashmap[temp[i]] + ' '
print(res)


from sys import stdin
[n, m] = map(int, stdin.readline().strip().split(' '))
lang_map = {}
sentence = []
new_sentence = []
for i in range(m):
	[l1, l2] = stdin.readline().strip().split(' ')
	lang_map[l1] = l2
sentence = stdin.readline().strip().split(' ')
for i in range(n):
	if len(sentence[i]) > len(lang_map[sentence[i]]):
		new_sentence.append(lang_map[sentence[i]])
	else:
		new_sentence.append(sentence[i])
new_sentence = ' '.join(new_sentence)
print(new_sentence)


(n, m) = map(int, input().split())
l = []
g = []
f = len
x = ''
for i in range(m):
	(a, b) = input().split()
	l.append(a)
	g.append(b)
t = list(input().split())
for i in t:
	if i in l:
		inde = l.index(i)
	else:
		inde = g.index(i)
	if f(l[inde]) > f(g[inde]):
		x += g[inde] + ' '
	else:
		x += l[inde] + ' '
print(x)


(n, m) = map(int, input().split())
x = []
y = []
s = []
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		x.append(b)
		y.append(a)
	else:
		x.append(a)
		y.append(b)
c = list(input().split())
for i in c:
	if i in x:
		s.append(i)
	elif i in y:
		temp = y.index(i)
		s.append(x[temp])
print(*s)


(n, m) = map(int, input().split())
l = []
while m:
	(a, b) = map(str, input().split())
	l.append((a, b))
	m = m - 1
s = list(map(str, input().split()))
l2 = []
for i in range(len(s)):
	for j in range(len(l)):
		if l[j][0] == s[i]:
			if len(l[j][0]) > len(l[j][1]):
				l2.append(l[j][1])
				break
			else:
				l2.append(l[j][0])
				break
		else:
			continue
print(*l2)


(n, m) = map(int, input().split())
words = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	if len(a) < len(b) or len(a) == len(b):
		words[b] = a
	else:
		words[a] = b
a = list(map(str, input().split()))
for i in range(n):
	if a[i] in words:
		a[i] = words[a[i]]
print(*a)


p = dict()
(n, m) = list(map(int, input().split()))
a = []
for i in range(m):
	h = input().split()
	if len(h[1]) > len(h[0]):
		p[h[1]] = h[0]
	if len(h[1]) < len(h[0]):
		p[h[0]] = h[1]
g = input().split()
for i in range(len(g)):
	if g[i] in p:
		g[i] = p[g[i]]
print(*g)


(n, m) = map(int, input().split(' '))
c = []
for i in range(m):
	(a, b) = map(str, input().split(' '))
	c.append(a)
	c.append(b)
l = input().split(' ')
le = [len(i) for i in c]
for w in l:
	index = c.index(w)
	if index % 2 == 0:
		if le[index + 1] < le[index]:
			index += 1
	elif le[index - 1] <= le[index]:
		index -= 1
	print(c[index], end=' ')


(n, m) = map(int, input().split())
f = []
s = []
ans = []
for i in range(m):
	(a, b) = input().split()
	f.append(a)
	s.append(b)
ip = list(input().split())
for i in ip:
	temp = s[f.index(i)]
	if len(temp) < len(i):
		ans.append(temp)
	else:
		ans.append(i)
for j in ans:
	print(j, end=' ')


def prog():
	from sys import stdin
	(n, m) = map(int, stdin.readline().split())
	di = {}
	for i in range(m):
		(a, b) = stdin.readline().split()
		di[a] = b
	s = map(str, stdin.readline().split())
	rez = ''
	for (i, x) in enumerate(s):
		if len(x) > len(di[x]):
			rez = '%s%s ' % (rez, di[x])
		else:
			rez = '%s%s ' % (rez, x)
	print(rez[:len(rez) - 1])
prog()


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		dic[a] = a
		dic[b] = a
	else:
		dic[a] = b
		dic[b] = b
x = list(map(str, input().split()))
s = ''
for i in x:
	s += dic[i] + ' '
print(s[:-1])


(n, m) = map(int, input().split())
dict = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	if len(a) == len(b) or len(a) < len(b):
		dict[a] = a
	else:
		dict[a] = b
name = input().split()
for i in name:
	print(dict[i], end=' ')


(n, m) = list(map(int, input().split()))
maps = dict()
for count in range(m):
	words = input().split()
	maps[words[0]] = words[1]
lecture = input().split()
for word in lecture:
	if len(word) > len(maps[word]):
		print(maps[word], end=' ')
	elif len(word) < len(maps[word]):
		print(word, end=' ')
	else:
		print(word, end=' ')


(n, m) = map(int, input().split())
(one, two) = ([], [])
final = []
for i in range(m):
	(c, a) = input().split()
	one.append(c)
	two.append(a)
s = map(str, input().split())
for i in s:
	if i in one:
		if len(i) > len(two[one.index(i)]):
			final.append(two[one.index(i)])
		else:
			final.append(i)
	elif len(i) > len(one[two.index(i)]):
		final.append(one[two.index(i)])
	else:
		final.append(i)
print(*final)


firstLine = [int(x) for x in input().split()]
d = {}
for i in range(0, firstLine[1]):
	temp = [str(x) for x in input().split()]
	if len(temp[0]) <= len(temp[1]):
		d[temp[1]] = temp[0]
	else:
		d[temp[0]] = temp[1]
lastLine = [str(x) for x in input().split()]
for s in lastLine:
	if s in d:
		print(d[s], '', end='')
	else:
		print(s, '', end='')


inp = input().split(' ')
change = {}
for x in range(int(inp[1])):
	a = input().split()
	if len(a[1]) < len(a[0]):
		change[a[0]] = a[1]
	else:
		change[a[0]] = a[0]
b = input().split(' ')
out = ''
c = b.pop(0)
out = out + change[c]
for y in b:
	out = out + ' ' + change[y]
print(out)


import sys
sys.setrecursionlimit(100000)

def main():
	(n, m) = map(int, input().split())
	first = list()
	second = list()
	M = {}
	for i in range(m):
		(x, y) = input().split()
		M[x] = y
	lecture = list(input().split())
	for word in lecture:
		(x, y) = (word, M[word])
		if len(x) <= len(y):
			print(x, end=' ')
		else:
			print(y, end=' ')
main()


(n, m) = map(int, input().split())
l = []
first = [None] * m
second = [None] * m
for i in range(m):
	(first[i], second[i]) = input().split()
s = input().split()
res = []
for str in s:
	for i in range(m):
		if str == first[i]:
			if len(first[i]) > len(second[i]):
				res.append(second[i])
			else:
				res.append(first[i])
			break
print(' '.join(res))


(n, m) = list(map(int, input().split()))
A = dict()
for i in range(m):
	(s, d) = input().split()
	A[s] = d
S = input().split()
d = ''
for i in range(n):
	if len(S[i]) <= len(A[S[i]]):
		d += S[i] + ' '
	else:
		d += A[S[i]] + ' '
print(d)


def Lecture():
	(n, m) = map(int, input().split())
	words = {}
	for i in range(m):
		(w1, w2) = input().split()
		if len(w2) < len(w1):
			words[w1] = w2
		else:
			words[w1] = w1
	inputarray = list(input().split())
	ans = []
	for i in inputarray:
		ans.append(words[i])
	print(*ans)

def main():
	Lecture()
main()


I = lambda : input().split()
(_, m) = map(int, I())
d = {}
for _ in range(m):
	(a, b) = I()
	if len(a) > len(b):
		d[a] = b
for c in I():
	print(d[c] if c in d else c, end=' ')


def inpNum():
	return int(input())

def inpNums():
	return map(int, input().split())

def inpList():
	return list(map(int, input().split()))

def inpStrMatrix(rows):
	return [list(input()) for _ in range(rows)]
(n, m) = inpNums()
words = dict()
for i in range(m):
	s = input().split()
	(l1, l2) = (len(s[0]), len(s[1]))
	if l1 > l2:
		words[s[0]] = s[1]
for t in input().split():
	if t in words:
		print(words[t], end=' ')
	else:
		print(t, end=' ')


(n, m) = map(int, input().split())
d = {}
l2 = []
for i in range(m):
	(s1, s2) = input().split()
	if len(s1) <= len(s2):
		l2.append(s1)
	else:
		l2.append(s2)
	if len(s1) <= len(s2):
		d[s1] = s2
	else:
		d[s2] = s1
l = list(input().split())
for i in l:
	if i in l2:
		print(i, end=' ')
	else:
		for (x, y) in d.items():
			if y == i:
				print(x, end=' ')


(n, m) = map(int, input().split())
d = {}
for x in range(m):
	c = input().split()
	(a, b) = c
	d[a] = b
l = [x for x in input().split()]
for x in range(len(l)):
	if len(l[x]) > len(d[l[x]]):
		l[x] = d[l[x]]
for x in l:
	print(x, end=' ')
print()


(n, m) = map(int, input().split())
dictionary = {}
for i in range(m):
	(a, b) = input().split()
	dictionary[a] = b
n = input().split()
for i in range(len(n)):
	if len(dictionary[n[i]]) < len(n[i]):
		n[i] = dictionary[n[i]]
print(*n)


(n, m) = list(map(int, input().split()))
d = dict()
for i in range(m):
	tmp = input().split()
	d[tmp[0]] = tmp[1]
s = input().split()
res = []
for word in s:
	if len(word) <= len(d[word]):
		res.append(word)
	else:
		res.append(d[word])
print(' '.join(res))


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
s = list(input().split())
ans = []
for i in range(len(s)):
	bs = a.index(s[i])
	if len(a[bs]) > len(b[bs]):
		ans.append(b[bs])
	else:
		ans.append(a[bs])
for i in ans:
	print(i, end=' ')


lijst = list(map(int, input().split(' ')))
woorden = []
woordenboek = {}
for i in range(0, lijst[1]):
	woorden.append(input().split(' '))
	if len(woorden[0][0]) <= len(woorden[0][1]):
		woordenboek[woorden[0][0]] = woorden[0][0]
	else:
		woordenboek[woorden[0][0]] = woorden[0][1]
	woorden = []
vertalen = list(map(str, input().split(' ')))
vertaling = ''
for i in range(0, lijst[0]):
	vertaling += ' ' + woordenboek[vertalen[i]]
print(vertaling[1:len(vertaling)])


import sys
cachedInput = sys.stdin
count = 0
totalNumberInLecture = 0
numberOfWordsInEachLanguage = 0
dictionary = {}
result = []

def returnShortest(list):
	if len(list[0]) <= len(list[1]):
		return list[0]
	else:
		return list[1]
line = input()
a = line.strip('\n').split()
totalNumberInLecture = int(a[0])
numberOfWordsInEachLanguage = int(a[1])
for line in cachedInput:
	count += 1
	if count <= numberOfWordsInEachLanguage:
		currentLine = line.strip('\n').split()
		dictionary[currentLine[0]] = returnShortest(currentLine)
	else:
		lecture = line.strip('\n').split()
for word in lecture:
	result.append(dictionary[word])
print(' '.join(result))


(n, m) = input().split()
n = int(n)
m = int(m)
dic = {}
for i in range(m):
	(t1, t2) = input().split()
	dic[t1] = t2
ans = []
lecture = input().split()
for word in lecture:
	if len(word) > len(dic[word]):
		ans.append(dic[word])
	else:
		ans.append(word)
print(*ans)


(n, m) = map(int, input().split())
(d, op) = ({}, '')
for _ in range(m):
	(a, b) = input().split()
	d[a] = b
arr = [i for i in input().split()]
for s in arr:
	if len(s) <= len(d[s]):
		op += s + ' '
	else:
		op += d[s] + ' '
print(op)


(N, T) = input('').split()
n = int(N)
t = int(T)
l = []
for i in range(0, t):
	s = input('').split()
	if len(s[0]) <= len(s[1]):
		a = [s[0], s[0]]
	else:
		a = [s[0], s[1]]
	l.append(a)
g = []
for i in l:
	g.append(i[0])
w = input('').split()
r = ''
for i in w:
	v = g.index(i)
	r = r + l[v][1] + ' '
print(r)


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	t = input()
	t = t.split()
	a[t[0]] = t[1]
ans = ''
s = input().split()
for i in range(len(s)):
	if len(s[i]) > len(a[s[i]]):
		s[i] = a[s[i]]
	ans = ans + s[i] + ' '
print(ans)


import sys

def FILE_IO():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, m) = map(int, input().split())
dic = dict()
for _ in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		b = a
	dic[a] = b
profes = list(input().split())
for word in profes:
	if word in dic:
		print(dic[word], end=' ')
	else:
		print(word, end=' ')


(n, m) = map(int, input().split())
dictionary = dict()
for _ in range(m):
	(first, second) = input().split()
	dictionary[first] = second
print(' '.join(list(map(lambda x: x if len(x) <= len(dictionary[x]) else dictionary[x], input().split()))))


(x, y) = list(map(int, input().split()))
t = {}
pr = []
for i in range(y):
	u = list(input().split())
	t[u[0]] = u[1]
f = input().split()
for j in range(len(f)):
	if len(t[f[j]]) < len(f[j]):
		pr.append(t[f[j]])
	else:
		pr.append(f[j])
print(*pr)


(n, k) = list(map(int, input().split()))
mapping = dict()
for i in range(k):
	(x, y) = input().split()
	mapping[x] = y
lecture = input().split()
ans = []
for word in lecture:
	if len(word) <= len(mapping[word]):
		ans.append(word)
	else:
		ans.append(mapping[word])
print(' '.join(ans))


(n, m) = map(int, input().split())
Words = []
for i in range(m):
	Words.append(input().split())
letter = input().split()
note = ''
for wanted in letter:
	for search in Words:
		if search[0] == wanted or search[1] == wanted:
			if len(search[0]) < len(search[1]):
				note += search[0] + ' '
			elif len(search[0]) > len(search[1]):
				note += search[1] + ' '
			else:
				note += search[0] + ' '
print(note)


(n, m) = [int(i) for i in input().split()]
dic = dict((input().split() for _ in range(m)))
c = [s for s in input().split()]
for i in range(n):
	s = c[i]
	t = dic[s]
	print(s if len(s) <= len(t) else t, end=' ')


[n, m] = [int(x) for x in input().split()]
ref = {}
for i in range(m):
	[a, b] = [x for x in input().split()]
	ref[a] = a if len(a) <= len(b) else b
s = ''
given = [x for x in input().split()]
for i in given:
	s += ref[i] + ' '
print(s[:-1])


(n, m) = map(int, input().split())
dict = {}
for i in range(m):
	(st1, st2) = input().split()
	l1 = len(st1)
	l2 = len(st2)
	if l1 <= l2:
		dict.update({st2: st1})
	else:
		dict.update({st1: st2})
li = input().split()
for i in range(n):
	if li[i] in dict:
		li[i] = dict[li[i]]
print(' '.join(li))


(n, m) = input().split()
n = int(n)
m = int(m)
f = []
for i in range(m):
	(s1, s2) = input().split()
	f.append((s1, s2))
f = sorted(f, key=lambda tup: tup[0])
st = ''
found = False
a = input().split()
for i in range(n):
	l = 0
	r = m - 1
	while l + 1 < r:
		b = (l + r) // 2
		if a[i] == f[b][0]:
			if len(f[b][0]) <= len(f[b][1]):
				st += f[b][0] + ' '
			else:
				st += f[b][1] + ' '
			found = True
			break
		elif a[i] < f[b][0]:
			r = b
		else:
			l = b
	if a[i] == f[r][0] and (not found):
		if len(f[r][0]) <= len(f[r][1]):
			st += f[r][0] + ' '
		else:
			st += f[r][1] + ' '
		found = True
	if a[i] == f[l][0] and (not found):
		if len(f[l][0]) <= len(f[l][1]):
			st += f[l][0] + ' '
		else:
			st += f[l][1] + ' '
	found = False
print(st)


(n, m) = map(int, input().split())
(a, b, res) = ([], [], [])
for i in range(m):
	(l, k) = map(str, input().split())
	a.append(l)
	b.append(k)
s = input().split()
for j in range(len(s)):
	ind = a.index(s[j])
	if len(s[j]) > len(b[ind]):
		res.append(b[ind])
	else:
		res.append(s[j])
print(*res)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
hash1 = dict()
for i in range(m):
	(a, b) = map(str, input().split())
	hash1[a] = b + '2'
	hash1[b] = a + '1'
ar = list(map(str, input().split()))
for i in range(len(ar)):
	s = hash1[ar[i]]
	if len(s) - 1 > len(ar[i]):
		print(ar[i], end=' ')
	elif len(s) - 1 < len(ar[i]):
		print(s[0:len(s) - 1:1], end=' ')
	elif s[len(s) - 1] == '1':
		print(s[0:len(s) - 1:1], end=' ')
	else:
		print(ar[i], end=' ')


def main():
	(n, m) = map(int, input().split())
	li = []
	while m > 0:
		(a, b) = input().split()
		li.append((a, b))
		m -= 1
	di = dict(li)
	li1 = list(input().split())
	for i in li1:
		if len(i) <= len(di[i]):
			print(i, end=' ')
		else:
			print(di[i], end=' ')
main()


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
(n, m) = list(map(int, input().split()))
d = {}
for l in range(m):
	(a, b) = input().split()
	d[a] = b
for word in input().split():
	print(min(word, d[word], key=lambda x: len(x)), end=' ')


(n, m) = map(int, input().split())
x = {}
for i in range(m):
	(a, b) = map(str, input().split())
	x[a] = b
lis = input().split()
res = []
for i in lis:
	if len(i) <= len(x[i]):
		res.append(i)
	else:
		res.append(x[i])
print(' '.join(res))


(n, m) = map(int, input().split())
haha1 = []
haha2 = []
final = []
for i in range(m):
	(hah, haha) = map(str, input().split())
	haha1.append(hah)
	haha2.append(haha)
string = input()
string = string.split(' ')
for i in string:
	if i in haha1:
		result = haha1.index(i)
		if len(haha1[result]) > len(haha2[result]):
			final.append(haha2[result])
		else:
			final.append(haha1[result])
	else:
		result = haha2.index(i)
		if len(haha1[result]) > len(haha2[result]):
			final.append(haha2[result])
		else:
			final.append(haha1[result])
final_result = ' '.join(final)
print(final_result)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(word_len, dict_len) = read_ints()
dicts = {}
for _ in range(dict_len):
	(one, two) = read_strs()
	dicts[one] = one if len(one) <= len(two) else two
print(' '.join((dicts[x] for x in read_strs())))


(n, m) = map(int, input().split())
d = dict()
for _ in range(m):
	(a, b) = input().split()
	x = [a, b][len(a) > len(b)]
	d[a] = d[b] = x
s = input().split()
for i in s:
	print(d[i], end=' ')


(n, k) = map(int, input().split())
(l, c) = ([], [])
for i in range(k):
	(x, y) = input().split()
	l.append(x)
	c.append(y)
p = ''
s = input().split()
for i in s:
	for j in range(k):
		if l[j] == i:
			if len(l[j]) <= len(c[j]):
				p += l[j]
			else:
				p += c[j]
	p += ' '
print(p)


t = input()
t = t.split()
n = int(t[0])
m = int(t[1])
a = dict()
for i in range(m):
	d = input()
	d = d.split()
	p = d[0]
	q = d[1]
	if len(p) > len(q):
		a[p] = q
b = input()
b = b.split()
for i in range(n):
	if b[i] in a:
		print(a[b[i]], end=' ')
	else:
		print(b[i], end=' ')


(n, m) = map(int, input().split())
(v, p) = ([], [])
for i in range(m):
	v.append(list(map(str, input().split())))
l = list(map(str, input().split()))
for i in range(len(v)):
	for j in range(len(l)):
		if v[i][0] == l[j] and len(v[i][0]) > len(v[i][1]):
			l[j] = v[i][1]
print(*l)


(n, m) = map(int, input().split())
d = {}
for z in range(m):
	(a, b) = input().split()
	d[a] = b
lecture = list(input().split())
for i in lecture:
	if len(i) <= len(d[i]):
		print(i, end=' ')
	else:
		print(d[i], end=' ')


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
d = {}
for i in range(m):
	(a, b) = input().split(' ')
	d[a] = b
	d[b] = a
l = []
c = input().split(' ')
for h in c:
	r1 = h
	r2 = d[h]
	if len(r1) <= len(r2):
		l.append(r1)
	else:
		l.append(r2)
print(' '.join(l))


(n, m) = input().split()
n = int(n)
m = int(m)
frst = []
scnd = []
for i in range(0, m):
	(x, y) = input().split()
	frst.append(x)
	scnd.append(y)
lecture = input()
word = lecture.split()
for i in range(0, m):
	if len(scnd[i]) < len(frst[i]):
		for j in range(0, n):
			if frst[i] == word[j]:
				word[j] = scnd[i]
print(' '.join(word))


from sys import stdin
input = stdin.readline
(n, m) = map(int, input().split())
dct = {}
for _ in range(m):
	(a, b) = input().split()
	dct[a] = b if len(b) < len(a) else a
print(*map(lambda w: dct[w], input().split()))


l1 = [int(x) for x in input().split()]
(n, m) = (l1[0], l1[1])
shorts = []
longs = []
for x in range(m):
	l4 = input().split()
	if len(l4[0]) > len(l4[1]):
		shorts.append(l4[1])
		longs.append(l4[0])
	else:
		shorts.append(l4[0])
		longs.append(l4[1])
words = input().split()
ans = []
for x in words:
	if x in shorts:
		ans.append(x)
	else:
		ans.append(shorts[longs.index(x)])
print(*ans)


w = input().split()
n = int(w[0])
m = int(w[1])
list1 = []
list2 = []
my_dict = {}
for i in range(m):
	flag = 0
	lang = input()
	arr = lang.split()
	my_dict[arr[0]] = arr[1]
mssg = input()
msg = mssg.split()
answer = ''
for i in range(len(msg)):
	if len(msg[i]) > len(my_dict[msg[i]]):
		msg[i] = my_dict[msg[i]]
for i in range(len(msg)):
	print(msg[i], end=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(f, s) = input().split()
	dic[f] = s
str1 = input().split()
str2 = ''
for s in str1:
	if len(s) > len(dic[s]):
		str2 += str(dic[s]) + ' '
	else:
		str2 += str(s) + ' '
print(str2)


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d.update({a: b})
ans = []
s = input().split()
for x in s:
	if len(x) > len(d[x]):
		ans.append(d[x])
	elif len(x) < len(d[x]):
		ans.append(x)
	else:
		ans.append(x)
print(*ans)


dict = {}
(a, b) = map(int, input().split())
for i in range(b):
	(x, y) = input().split()
	dict[x] = y
n = input().split()
a = []
for i in n:
	if len(i) == len(dict[i]):
		a.append(i)
	elif len(i) > len(dict[i]):
		a.append(dict[i])
	else:
		a.append(i)
print(*a)


(n, m) = map(int, input().split())
words = {}
for _ in range(m):
	(a, b) = input().split()
	words[a] = b
c = input().split()
out = []
for w in c:
	if len(words[w]) < len(w):
		out.append(words[w])
	else:
		out.append(w)
print(' '.join(out))


(n, m) = map(int, input().split())
dick = {}
for _ in ' ' * m:
	(a, b) = input().split()
	dick[a] = b if len(b) < len(a) else a
out = []
for i in input().split():
	out += [dick[i]]
print(*out)


def main():
	(n, m) = map(int, input().split())
	conv = {}
	for _ in range(m):
		(f, s) = input().split()
		conv[f] = s
	note = input().split()
	for i in note:
		alt = conv[i]
		if len(i) <= len(alt):
			print(i, end=' ')
		else:
			print(alt, end=' ')
main()


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(x, y) = map(str, input().split())
	d[x] = y
a = list(map(str, input().split()))
for i in range(n):
	if len(a[i]) <= len(d[a[i]]):
		print(a[i], end=' ')
	else:
		print(d[a[i]], end=' ')


(n, m) = map(int, input().split())
op = {}
dp = {}
for i in range(m):
	(a, b) = map(str, input().split())
	op[a] = b
l = list(map(str, input().split()))
ans = []
for i in l:
	if len(i) <= len(op[i]):
		ans.append(i)
	else:
		ans.append(op[i])
print(' '.join(ans))


(n, m) = map(int, input().split())
x = {}
for _ in range(m):
	(f, s) = map(str, input().split())
	if len(s) < len(f):
		(f, s) = (s, f)
	x[s] = f
test = list(map(str, input().split()))
for s in test:
	if s in x.keys():
		print(x[s], end=' ')
	else:
		print(s, end=' ')


(prof, lang) = map(int, input().strip().split())
arr = dict()
ans = []
for i in range(lang):
	s = input().split()
	arr[s[0]] = s[1]
speech = input().split()
for i in speech:
	if len(i) > len(arr[i]):
		ans.append(arr[i])
	else:
		ans.append(i)
print(' '.join(ans))


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(m):
	X = input().split()
	A = X[0]
	B = X[1]
	if len(A) > len(B):
		d[A] = B
		d[B] = B
	else:
		d[A] = A
		d[B] = A
string = list(input().split())
for word in string:
	print(d[word], end=' ')


class Fraction:

	def __init__(self, x='', y=''):
		self.first = x
		self.true = y

def replace(n):
	a = n.split()
	if len(a[0]) <= len(a[1]):
		return a[0]
	else:
		return a[1]
(n, m) = map(int, input().split())
change = []
for i in range(m):
	x = input()
	if replace(x) != x.split()[0]:
		change.append(Fraction(x.split()[0], replace(x)))
letter = input().split()
for i in range(n):
	for k in range(len(change)):
		if change[k].first == letter[i]:
			letter[i] = change[k].true
			break
ans = letter[0]
for i in range(1, len(letter)):
	ans = ans + ' ' + letter[i]
print(ans)


def main():
	[n, m] = [int(_) for _ in input().split()]
	dictionary = {}
	for _ in range(m):
		words = input().split()
		dictionary[words[0]] = words[1]
	message = input().split()
	for i in range(n):
		if len(dictionary[message[i]]) < len(message[i]):
			message[i] = dictionary[message[i]]
	print(' '.join(message))
main()


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	z = input().split()
	if len(z[0]) == len(z[1]):
		d[z[1]] = z[0]
	elif len(z[0]) > len(z[1]):
		d[z[0]] = z[1]
	else:
		d[z[1]] = z[0]
z = input().split()
s = ''
for i in z:
	if d.get(i, -1) == -1:
		d[i] = i
		s += d[i] + ' '
	else:
		s += d[i] + ' '
print(s)


(x, y) = map(int, input().split())
d = {}
for i in range(y):
	(xx, yy) = input().split()
	d[xx] = yy
l = input().split()
for i in l:
	if len(i) <= len(d[i]):
		print(i, end=' ')
	else:
		print(d[i], end=' ')
print()


(n, m) = map(int, input().split())
st1 = {}
st2 = {}
for i in range(m):
	s = input().split()
	(w1, w2) = (s[0], s[1])
	st1[w1] = w2
	st2[w2] = w1
test = input().split()
for x in test:
	w1 = x
	f = False
	if w1 in st1:
		f = True
		w2 = st1[w1]
	else:
		w2 = st2[w1]
	if len(w1) < len(w2):
		print(w1, end=' ')
	elif len(w2) < len(w1):
		print(w2, end=' ')
	else:
		print(w1 if f else w2, end=' ')


def trial():
	(n, m) = list(map(int, input().split()))
	short = {}
	for i in range(m):
		(a, b) = list(map(str, input().split()))
		if len(a) > len(b):
			short[a] = b
		else:
			short[a] = a
	case = list(map(str, input().split()))
	res = ''
	for i in case:
		res += short[i] + ' '
	return print(res)
trial()


(n, m) = map(int, input().split())
dict = {}
for i in range(m):
	(a, b) = input().split()
	dict[a] = b
k = input().split()
for i in k:
	if len(i) > len(dict[i]):
		k[k.index(i)] = dict[i]
print(*k)


(a, b) = map(int, input().strip().split()[:2])
a1 = []
b1 = []
for x in range(b):
	(p, q) = input().strip().split()[:2]
	a1.append(p)
	b1.append(q)
s = input().split()[:a]
for x in s:
	k = a1.index(x)
	l = b1[k]
	if len(l) < len(a1[k]):
		print(l, end=' ')
	else:
		print(a1[k], end=' ')


(a, b) = map(int, input().split())
d = {}
for i in range(b):
	(s, s1) = input().split()
	d[s] = s1
s2 = list(input().split())
r = ''
for k in s2:
	if k in d.keys():
		if len(k) <= len(d[k]):
			r += k + ' '
		else:
			r += d[k] + ' '
	elif k in d.values():
		if len(k) < d.key(k):
			r += k + ' '
		else:
			r += d.key(k) + ' '
print(r)


(n, m) = map(int, input().split())
set_ele = []
ans = ''
for i in range(m):
	(l1, l2) = input().split()
	if len(l2) < len(l1):
		set_ele.append(l2)
		set_ele.append(l1)
	else:
		set_ele.append(l1)
		set_ele.append(l2)
phrase = list(input().split())
for i in phrase:
	index = set_ele.index(i)
	if index % 2 == 0:
		ans += i + ' '
	else:
		ans += set_ele[index - 1] + ' '
print(ans)


(n, m) = map(int, input().split(' '))
dic = {}
for i in range(m):
	(a, b) = input().split(' ')
	if len(b) < len(a):
		s = b
	else:
		s = a
	dic[a] = s
	dic[b] = s
print(' '.join(map(lambda word: dic[word], input().split(' '))))


(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = d[b] = min(a, b, key=len)
s = input().split()
k = 0
for j in s:
	k += 1
	print(d[j] + ' \n'[k == n], end='')


import os
import sys
from math import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def array():
	return [int(i) for i in input().split()]
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
d = {}
(n, m) = map(int, input().split())
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
a = [i for i in input().split()]
for i in a:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
A = {}
for i in range(m):
	(a, b) = input().split()
	A[a] = b
s = input().split()
for i in s:
	l1 = len(i)
	l2 = len(A[i])
	if l1 <= l2:
		print(i, end=' ')
	else:
		print(A[i], end=' ')


(n, m) = map(int, input().split())
(l, k, f) = ([], [], [])
for i in range(m):
	b = list(input().split())
	l.append(b[0])
	k.append(b[1])
g = list(input().split())
for j in range(n):
	t = l.index(g[j])
	if len(l[t]) <= len(k[t]):
		f.append(l[t])
	else:
		f.append(k[t])
print(*f)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write()
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(n, m) = map(int, input().rstrip().split())
d = {}
for i in range(m):
	(s1, s2) = map(str, input().rstrip().split())
	if len(s1) <= len(s2):
		d[s1] = s1
	else:
		d[s1] = s2
l = list(map(str, input().rstrip().split()))
for i in l:
	print(d[i], end=' ')


def main():
	(res, wds) = [int(x) for x in input().split()]
	dic = {}
	for n in range(wds):
		(w1, w2) = input().split()
		dic[w1] = w2
	data = input().split()
	for val in data:
		print(val if len(val) <= len(dic[val]) else dic[val], end=' ')
main()


(n, m) = map(int, input().split())
list1 = []
list2 = []
for i in range(m):
	(a, b) = input().split()
	list1.append(a)
	list2.append(b)
list3 = input().split()
for i in range(n):
	k = list1.index(list3[i])
	if len(list1[k]) > len(list2[k]):
		list3[i] = list2[k]
print(' '.join(list3))


from collections import defaultdict
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
mymap = defaultdict(list)
for i in range(m):
	ab = list(map(str, input().split()))
	mymap[ab[0]].append(ab[1])
	mymap[ab[0]].append(1)
	mymap[ab[1]].append(ab[0])
	mymap[ab[1]].append(2)
inp = list(map(str, input().split()))
res = []
for c in inp:
	if len(c) < len(mymap[c][0]):
		res.append(c)
	elif len(c) > len(mymap[c][0]):
		res.append(mymap[c][0])
	elif len(c) == len(mymap[c][0]):
		if mymap[c][1] == 1:
			res.append(c)
		else:
			res.append(mymap[c][0])
for val in res:
	print(val, end=' ')


(n, m) = map(int, input().split())
d = dict()
for i in range(m):
	(s1, s2) = map(str, input().split())
	d[s1] = [s1, s2][len(s2) < len(s1)]
for word in input().split():
	print(d[word], end=' ')


(n, m) = map(int, input().strip().split())
d = {}
for i in range(m):
	(s1, s2) = input().strip().split()
	d[s1] = s1 if len(s1) <= len(s2) else s2
arr = input().strip().split()
print(' '.join([d[x] for x in arr]))


(n, m) = map(int, input().split())
dc = {}
for i in range(m):
	(a, b) = input().split()
	dc[a] = b
words = input().split()
for i in words:
	if len(i) <= len(dc[i]):
		print(i, end=' ')
	else:
		print(dc[i], end=' ')


(n, m) = map(int, input().split())
l = []
z = []
for i in range(m):
	(s, d) = map(str, input().split())
	l.append(s)
	l.append(d)
s = list(map(str, input().split()))
for i in range(len(s)):
	r = l.index(s[i])
	t = l[r + 1]
	if len(t) < len(s[i]):
		s[i] = t
print(*s)


(n, m) = [int(x) for x in input().split(' ')]
first = []
best = []
for i in range(m):
	(a, b) = [x for x in input().split(' ')]
	first.append(a)
	if len(a) <= len(b):
		best.append(a)
	else:
		best.append(b)
array = [x for x in input().split(' ')]
for x in array:
	print(best[first.index(x)], end=' ')


(n, m) = map(int, input().split())
(d1, d2) = (dict(), dict())
for i in range(m):
	(w1, w2) = map(str, input().split())
	(d1[w1], d2[w2]) = (w2, w1)
arr = list(map(str, input().split()))
for i in arr:
	if i in d1:
		(n1, n2) = (len(i), len(d1[i]))
		if n1 == n2:
			print(i, end=' ')
		elif n1 > n2:
			print(d1[i], end=' ')
		else:
			print(i, end=' ')
	elif i in d2:
		(n1, n2) = (len(i), len(d2[i]))
		if n1 == n2:
			print(d2[i], end=' ')
		elif n1 < n2:
			print(i, end=' ')
		elif n1 > n2:
			print(d2[i], end=' ')


(n, m) = [int(x) for x in input().split()]
d = dict()
for i in range(m):
	(a, b) = input().split()
	d[a] = b
l = input().split()
for i in range(n):
	if len(l[i]) > len(d[l[i]]):
		l[i] = d[l[i]]
print(' '.join(l))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	a = input().split()
	d[a[0]] = a[1]
x = input().split()
for i in range(n):
	if len(x[i]) > len(d[x[i]]):
		print(d[x[i]], end=' ')
	elif len(x[i]) <= len(d[x[i]]):
		print(x[i], end=' ')


(n, m) = map(int, input().strip().split())
words = []
for _ in range(m):
	word = tuple(input().strip().split())
	words.append(word)
sentence = input().strip().split()
ans = ''
for curr in sentence:
	for word in words:
		if word[0] == curr or word[1] == curr:
			if len(word[0]) <= len(word[1]):
				ans += word[0] + ' '
			else:
				ans += word[1] + ' '
print(ans)


(n, m) = map(int, input().split())
l1 = []
l2 = []
kl = ''
for i in range(m):
	(a, b) = map(str, input().split())
	l1.append(a)
	l2.append(b)
anst = input().split()
for i in anst:
	k = l1.index(i)
	l = min(len(l1[k]), len(l2[k]))
	if l == len(l1[k]):
		kl += str(l1[k])
		kl += ' '
	else:
		kl += str(l2[k])
		kl += ' '
print(kl)


(_, words) = [int(x) for x in input().split(' ')]
words_dict = dict()
numbers_dict = dict()
for index in range(words):
	(w1, w2) = [x for x in input().split(' ')]
	words_dict[w1] = words_dict[w2] = index
	numbers_dict[index] = w1 if len(w1) <= len(w2) else w2
lecture = [word for word in input().split(' ')]
for word in lecture:
	print(numbers_dict[words_dict[word]], end=' ')
print()


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	b.append(y)
s = list(map(str, input().split()))
f = []
for i in range(n):
	for j in range(m):
		if a[j] == s[i] or b[j] == s[i]:
			f.append(a[j]) if len(a[j]) <= len(b[j]) else f.append(b[j])
print(*f)


s = input().split()
n = int(s[0])
m = int(s[1])
mass1 = {}
mass2 = {}
for i in range(m):
	s = input().split()
	mass1[s[0]] = s[1]
	mass2[s[1]] = s[0]
s = input()
res = []
for st in s.split():
	if st in mass1:
		if len(st) <= len(mass1[st]):
			res.append(st)
		else:
			res.append(mass1[st])
	elif len(st) < len(mass2[st]):
		res.append(st)
	else:
		res.append(mass2[st])
print(' '.join(res))


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(s, t) = input().split()
	if len(t) < len(s):
		d[s] = t
for (i, s) in enumerate(input().split()):
	if i != 0:
		print(' ', end='')
	if s in d:
		print(d[s], end='')
	else:
		print(s, end='')
print('')


n1 = input().split()
i = 0
a = {}
while i < int(n1[1]):
	inn = input().split()
	a[inn[0]] = inn[1]
	i += 1
letters = input().split()
answers = ''
for i in letters:
	if len(i) <= len(a[i]):
		answers += i + ' '
	else:
		answers += a[i] + ' '
print(answers)


(n, m) = map(int, input().split(' '))
dict1 = {}
for _ in range(m):
	(str1, str2) = input().split(' ')
	dict1[str1] = str1 if len(str1) <= len(str2) else str2
inp = list(input().split(' '))
result = ''
for i in inp:
	result += dict1[i] + ' '
print(result)


(n, m) = map(int, input().split())
first = []
sec = []
for i in range(m):
	(l, r) = map(str, input().split())
	first.append(l)
	sec.append(r)
all_ = input()
lst = all_.split(' ')
rem = []
for j in range(0, len(lst)):
	if lst[j] in first:
		x = first.index(lst[j])
		if len(sec[x]) < len(first[x]):
			rem.append(sec[x])
		else:
			rem.append(first[x])
	elif lst[j] in sec:
		x = sec.index(lst[j])
		if len(first[x]) < len(sec[x]):
			rem.append(first[x])
		elif len(first[x]) > len(sec[x]):
			rem.append(sec[x])
		else:
			rem.append(first[x])
print(' '.join(rem))


from sys import stdin, stdout

def solve(text, dic):
	result = ''
	words = text.split()
	for word in words:
		result += '{} '.format(dic[word])
	return result.rstrip()
dic = {}
(n, m) = list(map(int, stdin.readline().rstrip().split()))
while m:
	m -= 1
	(l1, l2) = list(map(str, stdin.readline().rstrip().split()))
	if len(l2) < len(l1):
		dic[l1] = l2
	else:
		dic[l1] = l1
text = stdin.readline().rstrip()
stdout.write(str(solve(text, dic)))


(n, m) = [int(i) for i in input().split()]
s = []
s1 = []
s2 = []
for j in range(m):
	s = s + [str(i) for i in input().split()[:2]]
for i in range(len(s)):
	if i % 2 == 0:
		s1.append(s[i])
	else:
		s2.append(s[i])
f = [str(i) for i in input().split()[:n]]
v = []
for i in range(m):
	if len(s1[i]) < len(s2[i]):
		v.append(s1[i])
	elif len(s1[i]) == len(s2[i]):
		v.append(s1[i])
	else:
		v.append(s2[i])
for i in range(n):
	if f[i] in s1:
		c = s1.index(f[i])
	elif f[i] in s2:
		c = s2.index(f[i])
	if len(f[i]) > len(v[c]):
		f[i] = v[c]
g = ' '
print(g.join(f))


nums = input().split(' ')
n = int(nums[0])
m = int(nums[1])
dict = {}
res = list()
lst = list()
for i in range(m):
	lst = input().split(' ')
	t = {lst[0]: [lst[0], lst[1]]}
	dict.update(t)
lec = input().split(' ')
for i in range(n):
	if len(dict[lec[i]][0]) <= len(dict[lec[i]][1]):
		res.append(dict[lec[i]][0])
	else:
		res.append(dict[lec[i]][1])
print(*res)


(n, m) = map(int, input().split())
legend = []
for t in range(m):
	(a, b) = input().split()
	legend.append((a, b))
ans = list(input().split())
dictionary = {}
for j in legend:
	if len(j[0]) <= len(j[1]):
		dictionary[j[0]] = j[0]
	else:
		dictionary[j[0]] = j[1]
for i in range(n):
	ans[i] = dictionary[ans[i]]
ans = ' '.join(ans)
print(ans)


(n, m) = map(int, input().split())
first = []
second = []
for i in range(m):
	(a, b) = input().split()
	first.append(a)
	second.append(b)
c = input().split()
y = ''
for i in range(n):
	if c[i] in first:
		x = first.index(c[i])
	else:
		x = second.index(c[i])
	if len(first[x]) <= len(second[x]):
		y += first[x] + ' '
	else:
		y += second[x] + ' '
print(y)


n = list(map(int, input().rstrip().split()))
dctt = dict()
for i in range(n[1]):
	strr = list(map(str, input().rstrip().split()))
	if len(strr[0]) > len(strr[1]):
		dctt[strr[0]] = strr[1]
	else:
		dctt[strr[0]] = strr[0]
nn = list(map(str, input().rstrip().split()))
for i in nn:
	print(dctt[i], end=' ')


[n, m] = [int(x) for x in input().split()]
g = {}
for i in range(0, m):
	h = input().split()
	g[h[0]] = h[1]
f = input().split()
for i in f:
	if len(i) <= len(g[i]):
		print(i, end=' ')
	else:
		print(g[i], end=' ')


(n, m) = map(int, input().split())
d = dict()
for i in range(m):
	l = input().split()
	if len(l[0]) <= len(l[1]):
		d[l[0]] = l[0]
	else:
		d[l[0]] = l[1]
ans_list = input().split()
for i in range(n):
	print(d.get(ans_list[i]), end=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = input().split()
	dic[a] = b
lst = list(input().split())
for i in lst:
	print([i, dic[i]][len(i) > len(dic[i])], end=' ')


def lecture(dct, sentence):
	lst = []
	for word in sentence:
		mapp = dct[word]
		if len(mapp) < len(word):
			lst.append(mapp)
		else:
			lst.append(word)
	return ' '.join(lst)
(n, m) = map(int, input().split())
dct = {}
for _ in range(m):
	words = input().split(' ')
	dct[words[0]] = words[1]
sentence = input().split(' ')
print(lecture(dct, sentence))


num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
m = int(num_input[1])
map = {}
for i in range(0, m):
	input_string = input()
	input_string = input_string.split(' ')
	first = input_string[0]
	second = input_string[1]
	map[first] = second
n_string = input()
n_string = n_string.split(' ')
for i in range(0, len(n_string)):
	if len(n_string[i]) > len(map[n_string[i]]):
		n_string[i] = map[n_string[i]]
n_string = ' '.join(n_string)
print(n_string)


(n, m) = map(int, input().split())
k = dict()
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		k[a] = a
	else:
		k[a] = b
c = list(input().split())
for i in c:
	print(k[i], end=' ')


(n, m) = map(int, input().split())
d = {}
f = []
for i in range(m):
	c = {}
	e = {}
	(a, b) = input().split(' ')
	if len(a) <= len(b):
		c = {b: a}
		e = {a: a}
		d.update(c)
		d.update(e)
	else:
		c = {a: b}
		e = {b: b}
		d.update(c)
		d.update(e)
wq = list(input().split(' '))
for i in wq:
	f.append(d[i])
print(*f)


diction = {}
(n, m) = [int(i) for i in input().split()]
for i in range(m):
	(a, b) = [i for i in input().split()]
	diction[a] = b
lecture = [i for i in input().split()]
for (i, word) in enumerate(lecture):
	if len(word) > len(diction[word]):
		lecture[i] = diction[word]
sp = ' '
print(sp.join(lecture))


([n, m], word_map) = ([int(i) for i in input().split()], {})
for i in range(m):
	[word_1, word_2] = input().split()
	word = word_1 if len(word_1) <= len(word_2) else word_2
	word_map[word_1] = word
	word_map[word_2] = word
sentence = map(lambda x: word_map[x], input().split())
print(' '.join([x for x in sentence]))


import sys
(number, words) = map(int, sys.stdin.readline().split())
listofwords = dict()
for index in range(words):
	(w1, w2) = sys.stdin.readline().rstrip('\n').split()
	if len(w2) < len(w1):
		listofwords[w2] = w2
		listofwords[w1] = w2
	else:
		listofwords[w2] = w1
		listofwords[w1] = w1
lecture = sys.stdin.readline().rstrip('\n').split()
soln = [listofwords[word] for word in lecture]
print(' '.join(soln))


import sys
(n, m) = sys.stdin.readline().strip().split(' ')
(n, m) = (int(n), int(m))
d = {}
for i in range(0, m):
	(a, b) = sys.stdin.readline().strip().split(' ')
	if len(a) <= len(b):
		d[a] = a
		d[b] = a
	else:
		d[a] = b
		d[b] = b
l = sys.stdin.readline().strip().split(' ')
res = []
for s in l:
	res.append(d[s])
p = ' '
print(p.join(res))


p = input()
(n, m) = map(int, p.split())
q = []
w = []
for i in range(m):
	r = input()
	r = r.split()
	if len(r[0]) <= len(r[1]):
		w.append(r[0])
	else:
		w.append(r[1])
	q.append(r[0])
t = input()
t = t.split()
c = ''
for j in t:
	c += w[q.index(j)] + ' '
print(c)


(n, m) = map(int, input('').split())
l = [()]
for i in range(m):
	sp = input('').split()
	if len(sp[1]) >= len(sp[0]):
		sp[1] = ''
	l += [(sp[0], sp[1])]
p = list(map(str, input('').split(' ')))
l = l[1:]

def pppp(x):
	for i in l:
		if i[0] == x:
			if not i[1] == '':
				return i[1]
			else:
				return i[0]
k = ''
for i in range(len(p)):
	k += pppp(p[i]) + ' '
print(k[:-1])


(n, m) = map(int, input().split())
a = []
b = []
arr = []
for i in range(m):
	(q, w) = map(str, input().split())
	a.append(q)
	b.append(w)
c = list(map(str, input().split()))
for i in range(n):
	p = a.index(c[i])
	if len(a[p]) <= len(b[p]):
		arr.append(a[p])
	else:
		arr.append(b[p])
print(' '.join(arr))


def ii():
	return int(input())

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
(a, b) = mi()
s1 = {}
for i in range(b):
	it = input().split()
	s1[it[0]] = it[1]
c = input().split()
for i in c:
	if len(i) > len(s1[i]):
		print(s1[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = [int(i) for i in input().split()]
a = [0] * m
b = [0] * m
for i in range(m):
	(a[i], b[i]) = input().split()
res = ''
for i in input().split():
	ind = a.index(str(i))
	if len(a[ind]) > len(b[ind]):
		res += b[ind] + ' '
	else:
		res += a[ind] + ' '
print(res[:len(res) - 1])


first_line = list(map(int, input().split(' ')))
length_speech = first_line[0]
dictionary_len = first_line[1]
dict = {}
for i in range(dictionary_len):
	line = list(input().split(' '))
	dict[line[0]] = line[1]
speech = list(input().split(' '))
for i in range(len(speech)):
	w = speech[i]
	if len(dict[w]) < len(w):
		speech[i] = dict[w]
print(' '.join(speech))


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(st1, st2) = input().split()
	a.append(st1)
	b.append(st2)
l = list(input().split())
result = []
for item in l:
	if a.count(item) > 0:
		index = a.index(item)
		if len(a[index]) <= len(b[index]):
			result.append(a[index])
		else:
			result.append(b[index])
	else:
		index = b.index(item)
		if len(a[index]) <= len(b[index]):
			result.append(a[index])
		else:
			result.append(b[index])
print(*result)


(n, m) = map(int, input().split())
dictionary = []
for i in range(m):
	a = [i for i in input().split()]
	if len(a[1]) < len(a[0]):
		(a[0], a[1]) = (a[1], a[0])
	dictionary.append(a)
s = input().split()
for i in s:
	for j in dictionary:
		if i in j:
			print(j[0], end=' ')


(n, m) = map(int, input().split())
dc = {}
for i in range(m):
	a = input().split()
	dc[a[0]] = a[1]
mat = input().split()
for word in mat:
	if len(word) > len(dc[word]):
		print(dc[word], end=' ')
	else:
		print(word, end=' ')


(n, m) = map(int, input().split())
words = dict()
for _ in range(m):
	(s1, s2) = map(str, input().split())
	words[s1] = s2
res = ''
sent = input().split()
for word in sent:
	if len(word) > len(words[word]):
		res += words[word]
	else:
		res += word
	res += ' '
print(res)


n = int(input().split()[1])
d = {}
for i in range(0, n):
	a = input().split()
	d[a[0]] = a[1]
words = input().split()
ans = ''
for i in words:
	if len(d[i]) < len(i):
		ans += d[i]
	else:
		ans += i
	ans += ' '
ams = ans[:-1]
print(ans)


scann = input()
numbers = scann.split()
n = numbers[0]
m = numbers[1]
n_aux = int(n)
m_aux = int(m)
ultimo = [1]
b = []
s = [None for x in range(n_aux)]
for i in range(m_aux):
	hola = input()
	b.append(hola.split())
hola = input()
ultimo[0] = hola.split()
for i in range(n_aux):
	for j in range(m_aux):
		if ultimo[0][i] == b[j][0] or ultimo[0][i] == b[j][1]:
			if int(len(b[j][0])) <= int(len(b[j][1])):
				s[i] = b[j][0]
			else:
				s[i] = b[j][1]
print(' '.join(s))


D_1 = []
D_2 = []
Inpt = list(map(int, input().split()))
for I in range(Inpt[1]):
	In = list(map(str, input().split()))
	D_1.append(In[0])
	D_2.append(In[1])
M = list(map(str, input().split()))
Result = []
for I in range(len(M)):
	try:
		Ind = D_1.index(str(M[I]))
	except ValueError:
		Ind = D_2.index(str(M[I]))
	if len(D_2[Ind]) < len(D_1[Ind]):
		Result.append(D_2[Ind])
	else:
		Result.append(D_1[Ind])
for A in Result:
	print(A, end=' ')


(n, f) = map(int, input().split())
d = {}
for i in range(f):
	(a, b) = input().split()
	if len(a) > len(b):
		d[a] = b
	else:
		d[b] = a
s = list(input().split())
ans = []
for i in s:
	ans.append(d.get(i, i))
print(' '.join(ans))


(n, m) = map(int, input().split())
l1 = []
l2 = []
for _ in range(m):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
lect = list(input().split())
lp = []
for i in lect:
	ind = l1.index(i)
	if len(l2[ind]) < len(i):
		lp.append(l2[ind])
	else:
		lp.append(i)
print(*lp, sep=' ')


list_input = list(map(int, input().split()))
n = list_input[0]
m = list_input[1]
d = dict()
for i in range(m):
	words = input().split()
	shorter = ''
	if len(words[0]) <= len(words[1]):
		shorter = words[0]
	else:
		shorter = words[1]
	d[words[0]] = shorter
lectures = input().split()
for word in lectures:
	print(d[word], end=' ')


import functools
(n, m) = (int(x) for x in input().split(' '))
lang = {}
for i in range(0, m):
	(a, b) = (x for x in input().split(' '))
	if len(a) > len(b):
		lang[a] = b
	else:
		lang[b] = a

def shorter(x):
	if x in lang:
		return lang[x]
	else:
		return x
print(functools.reduce(lambda x, y: x + ' ' + y, [shorter(x) for x in input().split()]))


f = lambda : map(int, input().split())
(n, m) = f()
d = dict()
for i in range(m):
	(x, y) = input().split()
	d[x] = y
s = list(input().split())
for i in s:
	print([i, d[i]][len(i) > len(d[i])], end=' ')


d = dict()
(n, m) = map(int, input().split())
for i in range(m):
	pair = input().split()
	d[pair[0]] = pair[1]
s = input().split()
for word in s:
	if len(word) <= len(d[word]):
		print(word, end=' ')
	else:
		print(d[word], end=' ')


(n, m) = map(int, input().split())
words = {}
for i in range(m):
	(w1, w2) = input().split()
	if len(w2) < len(w1):
		words[w1] = w2
	else:
		words[w1] = w1
for word in input().split():
	print(words[word], end=' ')


(n, m) = map(int, input().split())
a = dict((input().split() for i in range(m)))
s = ''
for i in input().split():
	s = s + ' ' + min((i, a[i]), key=len)
print(s)


(n, m) = map(int, input().split())
a = {}
for _ in range(m):
	i = input().split()
	if len(i[0]) > len(i[1]):
		a[i[0]] = i[1]
c = input().split()
for x in c:
	if x in a:
		print(a[x], end=' ')
	else:
		print(x, end=' ')


(q, n) = list(map(int, input().split()))
d = {}
for _ in range(n):
	(a, b) = input().split()
	if len(a) > len(b):
		d[a] = b
	else:
		d[a] = a
s = input().split()
for i in s:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
d = dict()
for _ in range(m):
	(a, b) = input().split()
	d[a] = b if len(b) < len(a) else a
s = input().split()
a = []
for w in s:
	a.append(d[w])
print(' '.join(a))


(n, m) = map(int, input().split())
p = {}
p1 = {}
for i in range(m):
	(s1, s2) = map(str, input().split())
	if len(s2) < len(s1):
		p[s1] = s2
		p1[s1] = 1
	else:
		p[s2] = s1
		p1[s2] = int(1)
l = list(map(str, input().split()))
for i in range(n):
	try:
		print(p[l[i]], end=' ')
	except:
		print(l[i], end=' ')


(n, m) = map(int, input().split())
words = {}
for i in range(m):
	(a, b) = input().split()
	words[a] = a if len(a) <= len(b) else b
lecture = input().split()
print(' '.join((words[w] for w in lecture)))


(n, m) = map(int, input().split())
s = {}
for _ in range(m):
	(a, b) = input().split()
	s[a] = b
line = list(input().split())
for i in line:
	if len(i) > len(s[i]):
		print(s[i], end=' ')
	else:
		print(i, end=' ')


(n, m) = map(int, input().split())
l = list()
Acopy = list()
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		l.append(b)
	else:
		l.append(a)
	Acopy.append(a)
arr = list(input().split())
for i in range(n):
	print(l[Acopy.index(arr[i])], end=' ')


(n, m) = map(int, input().split())
dicts = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		b = a
	dicts[a] = b

def lookup(x):
	return dicts[x]
result = list(map(lookup, input().split()))
print(' '.join(result))


(n, m) = [int(i) for i in input().split()]
mydic = {}
for i in range(m):
	(first, second) = input().split()
	mydic[first] = second
a = input().split()
for elem in a:
	if len(mydic[elem]) < len(elem):
		print(mydic[elem], end=' ')
	else:
		print(elem, end=' ')


def main():
	(n, m) = map(int, input().split(' '))
	lan = {}
	for _ in range(m):
		(a, b) = map(str, input().split(' '))
		lan[a] = b
		lan[b] = a
	note = list(input().split(' '))
	ans = ''
	for w in note:
		temp = lan[w]
		ans += lan[temp] if len(lan[temp]) <= len(temp) else temp
		ans += ' '
	print(ans)
main()


(a, b) = map(int, input().split())
d = {}
for i in range(b):
	(c, e) = map(str, input().split())
	if len(c) <= len(e):
		e = c
	else:
		e = e
	d[c] = e
e = list(map(str, input().split()))
for i in e:
	print(d[i], end=' ')


(x, y) = map(int, input().split())
(li1, li2) = ([], [])
for i in range(y):
	(j, k) = input().split()
	li1.append(j)
	li2.append(k)
li = list(input().split())
ans = ''
for i in li:
	a = li1.index(i)
	if len(li1[a]) <= len(li2[a]):
		ans += f'{i} '
	else:
		ans += f'{li2[a]} '
print(ans)


(n, m) = map(int, input().split())
i = [input().split() for _ in range(m)]
language = {x: (x, y)[len(y) < len(x)] for (x, y) in i}
out = [language[x] for x in input().split()]
print(' '.join(out))


(n, m) = list(map(int, input().split()))
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = [1, b]
	d[b] = [2, a]
s = input().split()
for i in range(len(s)):
	if len(s[i]) > len(d[s[i]][1]):
		s[i] = d[s[i]][1]
	elif len(s[i]) == len(d[s[i]][1]):
		if d[s[i]][0] == 2:
			s[i] = d[s[i]][1]
print(' '.join(s))


a = []
b = []
(n, m) = map(int, input().split())
for i in range(m):
	(s1, s2) = input().split()
	a.append(s1)
	b.append(s2)
s = input().split()
for i in s:
	if len(a[a.index(i)]) <= len(b[a.index(i)]):
		print(a[a.index(i)], end=' ')
	else:
		print(b[a.index(i)], end=' ')


def main():
	rdl = list(map(int, input().split()))
	(n, m) = rdl
	words = []
	for i in range(m):
		rdl = input().split()
		words.append(rdl[0])
		words.append(rdl[1])
	rdl = input().split()
	ourNotePad = []
	for i in rdl:
		j = words.index(i)
		if j % 2 == 0:
			if len(words[j]) <= len(words[j + 1]):
				ourNotePad.append(words[j])
			else:
				ourNotePad.append(words[j + 1])
		elif len(words[j - 1]) <= len(words[j]):
			ourNotePad.append(words[j - 1])
		else:
			ourNotePad.append(words[j])
	for i in range(len(ourNotePad)):
		if i != len(ourNotePad) - 1:
			print(ourNotePad[i], end=' ')
		else:
			print(ourNotePad[i])
main()


(n, m) = map(int, input().split())
dic = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	dic[a] = b
s = list(map(str, input().split()))
ans = []
for i in s:
	if len(i) <= len(dic[i]):
		ans.append(i)
	else:
		ans.append(dic[i])
print(' '.join(ans))


i = lambda : input().split()
m = int(i()[1])
d = {}
for _ in [0] * m:
	(x, y) = i()
	a = min(x, y, key=len)
	d.update([(x, a), (y, a)])
print(*[d[x] for x in i()])


(lecture_length, dictionary_length) = map(int, input().split())
dictionary = {}
for i in range(dictionary_length):
	(source, translation) = input().split()
	dictionary[source] = translation
lecture = input().split()
res = []
for word in lecture:
	translation = dictionary[word]
	(source_lang_legth, knows_lang_length) = (len(word), len(translation))
	if source_lang_legth == knows_lang_length or source_lang_legth < knows_lang_length:
		res.append(word)
	else:
		res.append(translation)
print(' '.join(res))


(n, m) = map(int, input().split())
both_idioms = dict((input().split() for _ in range(m)))
a_list = [x for x in input().split()]
final_list = []
for key in a_list:
	value = both_idioms.get(key)
	if len(key) <= len(value):
		final_list.append(key)
	else:
		final_list.append(value)
print(' '.join(final_list))


dic = {}
(n, m) = map(int, input().split())
for i in range(m):
	(a, b) = input().split()
	dic[b] = a
	dic[a] = b
ls = []
m = input().split()
for i in range(len(m)):
	if len(m[i]) > len(dic[m[i]]):
		ls.append(dic[m[i]])
	else:
		ls.append(m[i])
print(*ls)


(a, b) = map(int, input().split(' '))
d = dict((input().split(' ') for i in range(b)))
print(' '.join((min((n, d[n]), key=len) for n in input().split(' '))))


(n, m) = map(int, input().split())
v = dict()
p = set()
for i in range(m):
	a = input().split()
	if len(a[0]) > len(a[1]):
		p.add(a[0])
		v[a[0]] = a[1]
c = input().split()
for i in range(n):
	if c[i] in p:
		print(v[c[i]], end=' ')
	else:
		print(c[i], end=' ')


(a, b) = map(int, input().split())
dic = {}
for i in range(b):
	a = input().split(' ')
	if len(a[0]) > len(a[1]):
		dic[a[0]] = a[1]
		dic[a[1]] = a[1]
	else:
		dic[a[0]] = a[0]
		dic[a[1]] = a[0]
t = input().split()
for i in range(len(t)):
	print(dic[t[i]], end=' ')


(n, m) = map(int, input().split())
(a, b) = ([''] * m, [''] * m)
for i in range(0, m):
	(a[i], b[i]) = map(str, input().split())
p = [str(x) for x in input().split()]
for i in p:
	if i in a:
		x = a.index(i)
		if len(a[x]) <= len(b[x]):
			print(a[x], end=' ')
		else:
			print(b[x], end=' ')
	else:
		x = b.index(i)
		if len(a[x]) <= len(b[x]):
			print(a[x], end=' ')
		else:
			print(b[x], end=' ')


(n, m) = input().split()
n = int(n)
m = int(m)
d = {}
for _ in range(m):
	(w1, w2) = input().split()
	if len(w1) > len(w2):
		d[w1] = w2
	else:
		d[w2] = w1
lecture = input().split()
ans = []
for word in lecture:
	if word in d:
		ans.append(d[word])
	else:
		ans.append(word)
print(' '.join(ans))


def main():
	(n, m) = map(int, input().split())
	trans = {}
	for i in range(m):
		(a, b) = input().split()
		if len(a) > len(b):
			trans[a] = b
		else:
			trans[a] = a
	s = input().split()
	notes = []
	for word in s:
		notes.append(trans[word])
	print(' '.join(notes))
main()


(n, m) = [int(x) for x in input().strip().split()]
word_dict = {}
for i in range(m):
	(a_i, b_i) = [str(x) for x in input().strip().split()]
	if len(a_i) <= len(b_i):
		word_dict[a_i] = a_i
		word_dict[b_i] = a_i
	else:
		word_dict[a_i] = b_i
		word_dict[b_i] = b_i
lecture_words = [str(x) for x in input().strip().split()]
translated_words = []
for word in lecture_words:
	translated_words.append(word_dict[word])
print(' '.join(translated_words))


(n, m) = map(int, input().split())
dict = {}
note = ''
for i in range(m):
	(word1, word2) = input().split()
	dict[word1] = word2
prof_words = list(input().split())
for word in prof_words:
	if len(word) <= len(dict[word]):
		note += word + ' '
	else:
		note += dict[word] + ' '
print(note)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[b] = a
		d[a] = a
	else:
		d[a] = b
		d[b] = b
lecture = input().split()
output = []
for w in lecture:
	output.append(d[w])
print(*output)


(n, m) = map(int, input().split())
words = dict()
for i in range(m):
	(a, b) = input().split()
	words[a] = b
lection = list(input().split())
for i in range(n):
	if len(lection[i]) > len(words[lection[i]]):
		lection[i] = words[lection[i]]
print(' '.join(lection))


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(k, v) = input().split()
	dic[k] = v
st = input().split()
for i in range(n):
	if len(dic[st[i]]) < len(st[i]):
		st[i] = dic[st[i]]
	else:
		pass
print(*st)


import re
replacement = dict()
(n, m) = map(int, input().split(' '))
for i in range(m):
	(lone, ltwo) = input().split(' ')
	if len(ltwo) < len(lone):
		replacement[lone] = ltwo
lecture = input()
for (word, repl) in replacement.items():
	lecture = re.sub('\\b%s\\b' % word, repl, lecture)
print(lecture)


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(x, y) = map(str, input().split())
	a.append(x)
	b.append(y)
lecture = list(map(str, input().split()))
for i in range(len(lecture)):
	indx = a.index(lecture[i])
	aLen = len(lecture[i])
	bLen = len(b[indx])
	if bLen < aLen:
		print(b[indx], end=' ')
	else:
		print(a[indx], end=' ')


(n, m) = map(int, input().split())
ans = []
dic = {}
for i in range(m + 1):
	if i == m:
		com = list(input().split())
	else:
		(a, b) = input().split()
		dic[a] = b
for item in com:
	if len(item) <= len(dic[item]):
		print(item, end=' ')
	else:
		print(dic[item], end=' ')


(n, m) = map(int, input().split())
(ans, s, d) = ([], [], [])
for i in range(m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		s.append(a)
		d.append(b)
	else:
		s.append(b)
		d.append(a)
p = list(map(str, input().split()))
for i in range(n):
	if p[i] not in s:
		temp = d.index(p[i])
		ans.append(s[temp])
	else:
		ans.append(p[i])
print(*ans)


from collections import defaultdict

def sexy(a, b):
	if len(a) > len(b):
		return b
	else:
		return a
(n, m) = map(int, input().split())
x = defaultdict(lambda : 'z' * 26)
for i in range(m):
	(a, b) = input().split()
	x[a] = b
y = input().split()
for i in y:
	print(sexy(i, x[i]), end=' ')
print()


(n, k) = map(int, input().split())
d = {}
v = []
for i in range(k):
	(x, y) = map(str, input().split())
	if x not in d:
		d[x] = y
s = list(map(str, input().split()))
for i in s:
	if i in d:
		if len(i) <= len(d[i]):
			v.append(i)
		else:
			v.append(d[i])
print(' '.join(v))


(n, m) = map(int, input().split())
lang = {}
for i in range(m):
	(x, y) = input().split()
	lang[x] = (x, y)
lect = input().split()
notes = []
for item in lect:
	one = len(lang[item][0])
	two = len(lang[item][1])
	if one > two:
		notes.append(lang[item][1])
	else:
		notes.append(lang[item][0])
print(*notes)


palavras = input().split()
dicionario = {}
for line in range(int(palavras[1])):
	termo = input().split()
	dicionario[termo[0]] = termo[1]
texto = input().split()
nova = []
for entrada in texto:
	if dicionario[entrada]:
		if len(dicionario[entrada]) >= len(entrada):
			nova.append(entrada)
		else:
			nova.append(dicionario[entrada])
	else:
		for (l1, l2) in dicionario.items():
			if l2 == entrada:
				if len(entrada) < len(l1):
					nova.append(entrada)
				else:
					nova.append(l1)
print(*nova)


t = input()
temp = t.split()
n = int(temp[0])
m = int(temp[1])
dictionary = dict()
for i in range(m):
	s = input()
	temp = s.split()
	dictionary[temp[0]] = temp[1]
s = input()
line = s.split()
for word in line:
	if len(word) > len(dictionary[word]):
		print(dictionary[word], ' ', end='')
	else:
		print(word, ' ', end='')


(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(m):
	(a, b) = [x for x in input().split()]
	if len(a) <= len(b):
		c = a
	else:
		c = b
	d[a] = c
	d[b] = c
text = input().split()
for word in text:
	print(d[word], end=' ')


(n, m) = [int(x) for x in input().split()]
d = {}
for _ in range(m):
	(s1, s2) = [x for x in input().split()]
	l1 = len(s1)
	l2 = len(s2)
	if l1 > l2:
		d[s1] = s2
	else:
		d[s1] = s1
arr = [x for x in input().split()]
for i in arr:
	print(d[i], end=' ')


(n, m) = [int(i) for i in input().split()]
d = {}
for j in range(m):
	s = input().split(' ')
	(n1, n2) = (len(s[0]), len(s[1]))
	(d[s[0]], d[s[1]]) = (s[1], s[0])
	if n1 > n2:
		d[s[1]] = s[1]
	else:
		d[s[0]] = s[0]
t = input().split(' ')
for elem in t:
	print(d[elem], end=' ')


a = list(map(int, input().split()))
m = a[0]
n = a[1]
i = 0
b = []
while i < n:
	b += list(map(str, input().split()))
	i += 1
c = list(map(str, input().split()))
z = 0
d = []
while z < m:
	t = b.index(c[z])
	k = list(b[t])
	i = len(k)
	if t % 2 == 0:
		f = list(b[t + 1])
		j = len(f)
		l = 1
	if t % 2 == 1:
		f = list(b[t - 1])
		j = len(f)
		l = -1
	if i <= j:
		d.append(b[t])
	else:
		d.append(b[t + l])
	z += 1
print(' '.join(d))


(n, m) = map(int, input().split())
mydict = {}
for i in range(m):
	(a, b) = map(str, input().split())
	if len(b) < len(a):
		mydict[a] = b
	else:
		mydict[a] = a
z = list(map(str, input().split()))
for i in z:
	print(mydict[i], end=' ')


(n, m) = list(map(int, input().split()))
s = list((sorted(input().split(), key=lambda x: len(x), reverse=0) for i in range(m)))
m = dict(((s[i // 2][i % 2], s[i // 2][0]) for i in range(m * 2)))
print(' '.join(list(map(lambda x: m[x], input().split()))))


(x, y) = map(int, input().split())
p = list()
for i in range(y):
	(a, b) = map(str, input().split())
	p.append(a)
	p.append(b)
k = list(map(str, input().split()))
for i in k:
	l = p.index(i) + 1
	if len(i) <= len(p[l]):
		print(i, end=' ')
	else:
		print(p[l], end=' ')


(x, y) = map(int, input('').split())
subList = []
for i in range(y):
	n = str(input()).split()
	subList.append(n[0])
	subList.append(n[1])
mainList = list(str(input()).split(' '))
finalList = []
for i in range(x):
	ind = subList.index(mainList[i])
	if len(subList[ind]) <= len(subList[ind + 1]):
		finalList.append(subList[ind])
	else:
		finalList.append(subList[ind + 1])
for i in finalList:
	print(i, end=' ')


(n, m) = map(int, input().strip().split(' '))
langa = {}
langb = {}
for i in range(m):
	tmp = input().split(' ')
	langa[tmp[0]] = [len(tmp[0]), tmp[1]]
	langb[tmp[1]] = len(tmp[1])
c = input().split(' ')
ans = ''
for j in c:
	if langa[j][0] <= langb[langa[j][1]]:
		ans += j + ' '
	else:
		ans += langa[j][1] + ' '
print(ans.strip())


(n, m) = [int(i) for i in input().split()]
d = dict()
for i in range(m):
	(s, s2) = input().split()
	d[s] = s2
for s in input().split():
	if len(d[s]) < len(s):
		print(d[s], end=' ')
	else:
		print(s, end=' ')


from sys import stdin
f = []
s = []
(n, m) = [int(c) for c in stdin.readline().split()]
for _ in range(0, m):
	(x, y) = stdin.readline().split()
	f.append(x)
	s.append(y)
ind = 0
note = ''
lecture = stdin.readline().split()
for w in lecture:
	ind = f.index(w)
	if len(s[ind]) < len(f[ind]):
		note = note + ' ' + s[ind]
	else:
		note = note + ' ' + w
print(note[1:])


(n, m) = map(int, input().split())
L1 = []
L2 = []
for i in range(m):
	(a, b) = map(str, input().split())
	L1.append(a)
	L2.append(b)
L = list(map(str, input().split()))
L3 = []
for i in range(len(L)):
	f = L1.index(L[i])
	if len(L1[f]) <= len(L2[f]):
		L3.append(L1[f])
	else:
		L3.append(L2[f])
a = ' '.join(L3)
print(a)


def min_by_len(a, b):
	if len(b) < len(a):
		return b
	else:
		return a
nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
translations = {}
for i in range(m):
	pair = input().split(' ')
	translations[pair[0]] = pair[1]
lecture = input()
result = ''
for word in lecture.split(' '):
	result += min_by_len(word, translations[word]) + ' '
print(result[:-1])


import sys

def read_from_stdin():
	(n, m) = input().split()
	language = {}
	for i in range(int(m)):
		(word1, word2) = input().split()
		if len(word1) > len(word2):
			language[word1] = word2
		else:
			language[word2] = word1
	lecture = input().split()
	return (lecture, language)

def write_to_stdout(res):
	sys.stdout.write('%s\n' % res)

def get_answer(lecture, language):
	new_lecture = []
	for word in lecture:
		if word in language:
			new_lecture.append(language[word])
		else:
			new_lecture.append(word)
	return ' '.join(new_lecture)

def main():
	(lecture, language) = read_from_stdin()
	res = get_answer(lecture, language)
	write_to_stdout(res)
main()


def chose_word(w, Languages):
	for l in Languages:
		if w in l:
			if len(l[0]) <= len(l[1]):
				return l[0]
			else:
				return l[1]
	return ''
(n, m) = map(int, input().split())
L = []
for i in range(m):
	language = input().split()
	L.append(language)
words = input().split()
for w in words:
	print(chose_word(w, L), end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d.update({a: b})
l = list(input().split())
for i in range(n):
	x = l[i]
	if len(x) > len(d[x]):
		l[i] = d[x]
for i in l:
	print(i, end=' ')
print()


(n, m) = map(int, input().split())
f1 = {}
for i in range(m):
	(x, y) = input().split()
	f1[x.strip()] = y.strip()
line = input().split()
res = ''
for i in range(len(line)):
	line[i] = line[i].strip()
	if len(f1[line[i]]) < len(line[i]):
		res = res + f1[line[i]] + ' '
	else:
		res = res + line[i] + ' '
print(res)


(n, m) = map(int, input().split())
d = dict((input().split() for i in range(m)))
S = input().split()
c = 1
S1 = ''
for x in S:
	if len(x) <= len(d[x]):
		v = x
	else:
		v = d[x]
	if c == 1:
		S1 = v
		c = 0
	else:
		S1 = S1 + ' ' + v
print(S1)


(n, m) = map(int, input().split())
l1 = []
l = []
for i in range(m):
	(a, b) = map(str, input().split())
	l.extend([a, b])
s = input().split()
ans = ''
for i in range(n):
	word = s[i]
	ind = l.index(word)
	if ind & 1 == 0:
		other = l[ind + 1]
	else:
		other = l[ind - 1]
	if len(word) <= len(other):
		l1.append(word)
	else:
		l1.append(other)
print(*l1)


(n, m) = map(int, input().split())
s = {}
for _ in [0] * m:
	(a, b) = input().split()
	s[a] = s[b] = b if len(b) < len(a) else a
t = input().split()
for i in range(n):
	t[i] = s[t[i]]
print(' '.join(t))


(n, m) = [int(i) for i in input().split()]
dictionary = {}
for j in range(m):
	(word_1, word_2) = [i for i in input().split()]
	if len(word_1) > len(word_2):
		dictionary[word_1] = word_2
	else:
		dictionary[word_1] = word_1
lection = input().split()
result = ''
for word in lection:
	result += dictionary[word] + ' '
print(result[:-1])


(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(b) < len(a):
		d[a] = b
	else:
		d[a] = a
text = input().split()
ans = []
for i in text:
	ans.append(d[i])
print(*ans)


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(i, j) = input().split()
	le = len(i)
	lj = len(j)
	if le < lj:
		d[i] = i
	elif le > lj:
		d[i] = j
	else:
		d[i] = i
string = input().split()
for j in string:
	x = d[j]
	print(x, end='')
	print(' ', end='')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
res = ''
for word in input().split():
	res += d[word] + ' '
print(res[:-1])


(n, m) = map(int, input().strip().split(' '))
d = {}
for _ in range(m):
	(a, b) = input().strip().split(' ')
	d[a] = b
txt = input().strip().split(' ')
for i in range(len(txt)):
	tmp = d[txt[i]]
	if len(tmp) < len(txt[i]):
		txt[i] = tmp
print(' '.join(txt))


from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(str, input().split()))
(n, m) = M()
d = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	d[a] = b
a = LI()
b = []
for i in range(len(a)):
	if len(a[i]) > len(d[a[i]]):
		b += [d[a[i]]]
	else:
		b += [a[i]]
print(*b)


def call():
	(n, m) = map(int, input().split())
	k = {}
	for _ in range(m):
		(a, b) = map(str, input().split())
		x = (b, a)[len(a) <= len(b)]
		k[a] = x
		k[b] = x
	tc = [x for x in input().split()]
	s = ''
	for i in tc:
		s += k[i]
		s += ' '
	print(s)
call()


def search(li, i):
	start = 0
	end = len(li)
	while start <= end:
		mid = (start + end) // 2
		if li[mid][0] == i:
			break
		elif li[mid][0] > i:
			end = mid - 1
		else:
			start = mid + 1
	if len(li[mid][0]) <= len(li[mid][1]):
		return li[mid][0]
	else:
		return li[mid][1]

def sort2(li, sent):
	li.sort(key=lambda x: x[0])
	for i in sent:
		print(search(li, i), end=' ')
(n, m) = [int(x) for x in input().split()]
li = []
for i in range(m):
	x = [x for x in input().split()]
	li.append(x)
sent = [x for x in input().split()]
sort2(li, sent)


__author__ = 'runekri3'
(n, m) = map(int, input().split())
first_language = []
second_language = []
second_is_shorter = []
for _ in range(m):
	(first, second) = input().split()
	first_language.append(first)
	second_language.append(second)
	second_is_shorter.append(len(first) > len(second))
final_words = []
for word in input().split():
	index = first_language.index(word)
	if second_is_shorter[index]:
		final_words.append(second_language[index])
	else:
		final_words.append(word)
print(' '.join(final_words))


(n, m) = map(int, input().strip().split())
a = {}
for i in range(m):
	(x, y) = map(str, input().strip().split())
	a[x] = y
arr = list(map(str, input().strip().split()))
ans = []
for i in range(len(arr)):
	if len(a[arr[i]]) < len(arr[i]):
		ans.append(a[arr[i]])
	else:
		ans.append(arr[i])
print(*ans)


a = list(map(int, input().split()))
b = list()
trash = list()
for i in range(a[1]):
	c = input().split()
	if len(c[1]) < len(c[0]):
		b.append(c[1])
		trash.append(c[0])
	else:
		b.append(c[0])
		trash.append(c[1])
d = input().split()
ans = ''
for i in range(len(d)):
	for x in range(len(b)):
		if d[i] == trash[x]:
			d[i] = b[x]
			break
	ans += d[i] + ' '
print(ans)


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(str)
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
s = input().split()
print(' '.join((d[i] for i in s)))


def func(n):
	dictionary = dict((input().split() for i in range(n[1])))
	text = input().split()
	ans = []
	for i in text:
		ans.append(min(i, dictionary[i], key=len))
	print(' '.join(ans))
n = list(map(int, input().split()))
func(n)


(n, m) = [int(x) for x in input().split()]
l = dict()
for _ in range(m):
	(a, b) = [str(x) for x in input().split()]
	l[a] = b
q = [str(x) for x in input().split()]
ans = []
for x in q:
	fl = x
	sl = l[x]
	if len(fl) == len(sl):
		ans.append(fl)
	else:
		ans.append(fl if len(fl) < len(sl) else sl)
print(' '.join(ans))


(n, m) = map(int, str(input()).split(' '))
word_map = {}
for i in range(m):
	(a, b) = str(input()).split(' ')
	word_map[a] = b
l = str(input()).split(' ')
f = ''
for w in l:
	f += w if len(w) <= len(word_map[w]) else word_map[w]
	f += ' '
print(f)


(n, m) = input().split()
n = int(n)
m = int(m)
b = dict()
for i in range(m):
	(x, y) = input().split()
	if len(x) <= len(y):
		b[x] = x
	else:
		b[x] = y
c = input().split()
for i in range(n):
	print(b[c[i]], end=' ')


(n, m) = map(int, input().split())
shorter = []
longer = []
for i in range(m):
	(word1, word2) = map(str, input().split())
	if len(word1) <= len(word2):
		shorter.append(word1)
		longer.append(word2)
	else:
		shorter.append(word2)
		longer.append(word1)
lecture = map(str, input().split())
for word in lecture:
	if word in longer:
		print(shorter[longer.index(word)], end=' ')
	else:
		print(shorter[shorter.index(word)], end=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(x, y) = input().split()
	dic[x] = y
a = list(input().split())
print(*[i if len(i) <= len(dic[i]) else dic[i] for i in a])


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		(a, b) = (b, a)
	dic[a] = a
	dic[b] = a
line = input().split()
ans = [dic[i] for i in line]
print(*ans)


(n, m) = input().split()
(n, m) = (int(n), int(m))
lis = []
for i in range(m):
	lis.append(input().split())

def decide(lis):
	if len(lis[0]) <= len(lis[1]):
		return lis[0]
	else:
		return lis[1]
dic = {}
for i in range(m):
	dic[lis[i][0]] = decide(lis[i])
lec = input().split()
for i in range(n):
	print(dic[lec[i]], end=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
		d[b] = a
	else:
		d[b] = b
		d[a] = b
s = list(input().split())
for e in s:
	print(d[e], end=' ')


(n, m) = map(int, input().split())
d = dict()
for i in range(m):
	a = list(map(str, input().split()))
	d[a[0]] = [a[1], a[0]]
s = list(map(str, input().split()))
for i in range(len(s)):
	if len(d[s[i]][0]) < len(d[s[i]][1]):
		print(d[s[i]][0], end=' ')
	else:
		print(d[s[i]][1], end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = input().split()
	d[a] = b
msg = [s for s in input().split()]
for s in msg:
	a = s
	b = d[s]
	if len(a) <= len(b):
		print(a, end=' ')
	else:
		print(b, end=' ')


def swap_words():
	(n, m) = map(int, input().split())
	words = dict()
	for i in range(0, m):
		(k, v) = input().split()
		words[k] = v
	for w in input().split():
		w2 = words[w]
		if len(w2) < len(w):
			yield w2
		else:
			yield w
print(' '.join(swap_words()))


(n, m) = map(int, input().split(' '))
dic = {}
for i in range(m):
	(first, second) = map(str, input().split(' '))
	dic[first] = second
lecture = list(map(str, input().split()))
for i in range(len(lecture)):
	if len(dic[lecture[i]]) < len(lecture[i]):
		lecture[i] = dic[lecture[i]]
print(' '.join(lecture))


s = input().strip().split()
(n, m) = (int(s[0]), int(s[1]))
dic = dict()
for i in range(m):
	s = input().strip().split()
	dic[s[0]] = s[1]
s = input().strip().split()
for i in s:
	if len(i) <= len(dic[i]):
		print(i, end=' ')
	else:
		print(dic[i], end=' ')


def main(lecter, dictt):
	res = []
	d = dict(dictt)
	for i in lecter:
		if len(i) <= len(d.get(i)):
			res.append(i)
		else:
			res.append(d.get(i))
	return ' '.join([str(i) for i in res])
(n, m) = list(map(int, input().split()))
dictt = []
for i in range(m):
	dictt.append(list(input().split()))
lecter = list(input().split())
print(main(lecter, dictt))


(n, m) = map(int, input().split())
l = []
first = []
second = []
for i in range(m):
	(a, b) = input().split()
	first.append(a)
	second.append(b)
s = input().split()
res = ''
for str in s:
	for i in range(m):
		if str == first[i]:
			if len(first[i]) > len(second[i]):
				res += second[i] + ' '
			else:
				res += first[i] + ' '
			break
print(res)


(n, m) = map(int, input().split())
L = {}
for i in range(m):
	a = input().split()
	x = a[0]
	y = a[1]
	L[x] = y
Z = input().split()
x = ''
for i in Z:
	if len(i) <= len(L[i]):
		x += i + ' '
	else:
		x += L[i] + ' '
print(x)


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	word = input().split()
	dic[word[0]] = word[1]
c = input().split()
for i in range(n):
	if len(dic[c[i]]) < len(c[i]):
		c[i] = dic[c[i]]
print(*c)


(n, m) = [int(a_temp) for a_temp in input().strip().split()]
d = {}
for _ in range(m):
	t = [str(a_temp) for a_temp in input().strip().split()]
	d[t[0]] = t[1] if len(t[1]) < len(t[0]) else t[0]
w = [str(a_temp) for a_temp in input().strip().split()]
for i in range(n):
	w[i] = d[w[i]]
print(' '.join(w))


x = input().strip().split(' ')
n = int(x[0])
m = int(x[1])
(i, j) = (0, 0)
notes = []
language = []
for i in range(0, m):
	(language1, language2) = input().strip().split(' ')
	if len(language1) > len(language2):
		language.append([language2, language1])
	else:
		language.append([language1, language2])
lecture = input().strip().split(' ')
for i in range(0, n):
	for j in range(0, m):
		if language[j][0] == lecture[i] or language[j][1] == lecture[i]:
			notes.append(language[j][0])
for x in notes:
	print(x, end=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = list(input().split())
	d[a] = b
c = list(input().split())
r = []
for s in c:
	a = s
	b = d[s]
	if len(a) > len(b):
		r.append(b)
	else:
		r.append(a)
print(' '.join(r))


(n, m) = (int(X) for X in input().split())
rulebook = []
for i in range(m):
	rulebook.append([X for X in input().split()])
text = [X for X in input().split()]
output = ''
for X in text:
	for i in range(m):
		if rulebook[i][0] == X:
			if len(rulebook[i][0]) > len(rulebook[i][1]):
				output += rulebook[i][1] + ' '
			else:
				output += rulebook[i][0] + ' '
print(output)


import re
(n, m) = map(int, input().split())
words = []
for i in range(m):
	words.append([i for i in input().split()])
words = sum(words, [])
text = input()
wordList = re.sub('[^\\w]', ' ', text).split()
for i in wordList:
	x = words.index(i)
	if x % 2 == 1:
		print(words[x] if len(words[x]) < len(words[x - 1]) else words[x - 1], end=' ')
	else:
		print(words[x] if len(words[x]) <= len(words[x + 1]) else words[x + 1], end=' ')


a = input().split()
n = int(a[0])
m = int(a[1])
b = []
c = {}
for i in range(m):
	b = input().split()
	if len(b[0]) <= len(b[1]):
		c[b[0]] = b[0]
	else:
		c[b[0]] = b[1]
b = input().split()
d = []
for i in range(n):
	d.append(c[b[i]])
print(' '.join(d))


(n, m) = list(map(int, input().split()))
dictory = {}
while m > 0:
	words = list(map(str, input().split()))
	if len(words[0]) <= len(words[1]):
		dictory[words[0]] = words[0]
	else:
		dictory[words[0]] = words[1]
	m -= 1
text = list(map(str, input().split()))
str_output = ''
for element in text:
	str_output += ' ' + dictory[element]
print(str_output.strip())


(n, m) = map(int, input().split())
d = dict()
for i in range(m):
	k = input().split()
	a = k[0]
	b = k[1]
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
a = input().split()
for i in range(n):
	print(d[a[i]], end=' ')


l = input().split()
(q, n) = (int(l[0]), int(l[1]))
(a, b, c) = ([], [], [])
for i in range(n):
	s = input().split()
	(s1, s2) = (str(s[0]), str(s[1]))
	a.append(s1)
	if len(s2) < len(s1):
		b.append(s2)
	else:
		b.append(s1)
s = list(map(str, input().split()))
for i in range(q):
	c.append(b[a.index(s[i])])
print(' '.join(c))


def mi():
	return map(int, input().split(' '))
(m, n) = mi()
d = {}
for i in range(n):
	(x, y) = map(str, input().split(' '))
	if len(x) <= len(y):
		d[x] = x
		d[y] = x
	else:
		d[x] = y
		d[y] = y
li = [x for x in input().split(' ')]
for i in li:
	print(d[i], end=' ')


t = [int(x) for x in input().split()]
(n, m) = (t[0], t[1])
(f, s) = ([], [])
for i in range(m):
	p = input().split()
	f.append(p[0])
	s.append(p[1])
lecture = input().split()
z = [s[f.index(i)] if len(s[f.index(i)]) < len(i) else i for i in lecture]
print(' '.join(z))


(n, m) = list(map(int, input().split()))
a_to_b = dict()
for _ in range(m):
	(a, b) = input().split()
	a_to_b[a] = b if len(b) < len(a) else a
lecture = input().split()
answer = [a_to_b[i] for i in lecture]
temp = ' '.join(answer)
print(temp)


(n, m) = map(int, input().split())
lang = {}
for _ in range(m):
	(a, b) = input().split()
	lang[a] = b
lec = list(input().split())
for (i, word) in enumerate(lec):
	if len(lang[word]) < len(word):
		lec[i] = lang[word]
print(' '.join(lec))


(n, m) = map(int, input().split())
lst = []
for i in range(m):
	lst.append(input().split())
ai = list(map(str, input().split()))
for i in ai:
	for j in lst:
		if i in j:
			if len(j[0]) > len(j[1]):
				print(j[1], end=' ')
			elif len(j[1]) > len(j[0]):
				print(j[0], end=' ')
			else:
				print(j[0], end=' ')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(s1, s2) = map(str, input().split())
	if len(s1) <= len(s2):
		d[s1] = s1
	else:
		d[s1] = s2
sentence = [i for i in map(str, input().split())]
result = []
for letter in sentence:
	result.append(d[letter])
print(' '.join(result))


(n, m) = map(int, input().split())
language = {}
for i in range(m):
	(a, b) = map(str, input().split())
	language[a] = min([a, b], key=lambda x: len(x))
notes = input().split()
res = ''
for i in notes:
	res += language[i] + ' '
print(res.strip())


(n, m) = map(int, input().split())
d1 = []
d2 = []
for _ in range(m):
	(a, b) = input().split()
	d1.append(a)
	d2.append(b)
lec = list(input().split())
for i in range(n):
	if lec[i] in d1:
		ind = d1.index(lec[i])
	else:
		ind = d2.index(lec[i])
	if len(d1[ind]) <= len(d2[ind]):
		lec[i] = d1[ind]
	else:
		lec[i] = d2[ind]
print(*lec)


(a, b) = map(int, input().split())
c = []
d = []
ans = ''
for i in range(0, b):
	(o, p) = map(str, input().split())
	c.append(o)
	d.append(p)
q = list(map(str, input().split()))
for j in q:
	e = c.index(j)
	f = d[e]
	if len(j) > len(f):
		ans += str(f) + ' '
	else:
		ans += str(j) + ' '
print(ans)


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
from math import ceil
(n, m) = ei()
d = {}
for i in range(m):
	(f, s) = input().split()
	d[f] = [len(s), s]
main = input().split()
for i in range(len(main)):
	if len(main[i]) > d[main[i]][0]:
		main[i] = d[main[i]][1]
print(*main)


r = {}
(n, m) = input().split()
for i in range(int(m)):
	(a, b) = input().split()
	if len(b) < len(a):
		r[a] = b
	else:
		r[a] = a
l = []
f = [i for i in input().split()]
for i in range(int(n)):
	l.append(r[f[i]])
print(*l)


def f(l, a):
	for i in range(0, len(l), 2):
		if l[i] == a:
			if len(a) > len(l[i + 1]):
				return l[i + 1]
			else:
				return a
(n, m) = map(int, input().split())
l = []
for i in range(m):
	l1 = list(input().split())
	l.append(l1[0])
	l.append(l1[1])
s = list(input().split())
for i in range(n):
	print(f(l, s[i]), end=' ')


(n, m) = input().split()
(n, m) = (int(n), int(m))
l = []
for i in range(m):
	(a, b) = input().split()
	l.append(a)
	l.append(b)
s = input().split()
s1 = []
for i in range(len(s)):
	x = l.index(s[i])
	if len(l[x + 1]) < len(l[x]):
		s1.append(l[x + 1])
	elif len(l[x + 1]) >= len(l[x]):
		s1.append(l[x])
print(*s1)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(x, y) = input().split()
	d[x] = y
s = list(input().split())
p = ''
for i in s:
	if len(i) <= len(d[i]):
		p += i + ' '
	else:
		p += d[i] + ' '
print(p)


from sys import stdin
(n, m) = [int(i) for i in stdin.readline().split()]
d = {}
for i in range(m):
	(f, s) = [j for j in stdin.readline().split()]
	if len(f) > len(s):
		d[s] = s
		d[f] = s
	else:
		d[s] = f
		d[f] = f
w = [i for i in stdin.readline().split()]
for i in w:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
dict = {}
for i in range(m):
	(str1, str2) = input().split()
	dict[str1] = str2
prof = input().split()
res = []
for i in prof:
	if len(dict[i]) < len(i):
		res.append(dict[i])
	else:
		res.append(i)
res = ' '.join(res)
print(res)


s = str(input()).split()
s[0] = int(s[0])
s[1] = int(s[1])
l = [[], []]
for i in range(s[1]):
	p = str(input()).split()
	l[0].append(p[0])
	l[1].append(p[1])
s = str(input()).split()
for i in range(len(s)):
	j = l[0].index(s[i])
	if len(l[0][j]) <= len(l[1][j]):
		print(l[0][j], end=' ')
	else:
		print(l[1][j], end=' ')


(n, m) = (int(x) for x in input().split())
ab = {}
for i in range(m):
	x = input().split()
	ab[x[0]] = x[1]
s = ' '.join((w if len(w) <= len(ab[w]) else ab[w] for w in input().split()))
print(s)


from sys import stdin
from collections import defaultdict
input = lambda : stdin.readline().strip()
(a, b) = list(map(int, input().split()))
dict1 = defaultdict()
for _ in range(b):
	(c, d) = input().split()
	if len(d) < len(c):
		dict1[c] = d
	else:
		dict1[c] = c
s = input().split()
for i in s:
	print(dict1[i], end=' ')
print()


(m, n) = list(map(int, input().split()))
(l, r) = ([], [])
for _ in range(n):
	(p, q) = list(input().split())
	l.append(p)
	r.append(q)
(t, u) = (input().split(), '')
for i in t:
	if i in l:
		if len(l[l.index(i)]) == len(r[l.index(i)]):
			u = u + l[l.index(i)] + ' '
		elif len(l[l.index(i)]) < len(r[l.index(i)]):
			u = u + l[l.index(i)] + ' '
		else:
			u = u + r[l.index(i)] + ' '
	elif len(l[r.index(i)]) == len(r[r.index(i)]):
		u = u + l[r.index(i)] + ' '
	elif len(l[r.index(i)]) < len(r[r.index(i)]):
		u = u + l[r.index(i)] + ' '
	else:
		u = u + r[r.index(i)] + ' '
print(u)


def short(s1, s2):
	if len(s1) < len(s2):
		return s1
	elif len(s1) > len(s2):
		return s2
	else:
		return s1
(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(a, b) = map(str, input().split())
	if a not in d:
		d[a] = b
L = list(input().split())
s = ''
for c in L:
	print(short(c, d[c]), end=' ')


(n, m) = map(int, input().split())
first = []
second = []
t = 0
while t < m:
	(a, b) = input().split()
	first.append(a)
	second.append(b)
	t = t + 1
lecture = input().split()
for i in lecture:
	if len(i) > len(second[first.index(i)]):
		lecture[lecture.index(i)] = second[first.index(i)]
print(' '.join(lecture))


sen = input().split(' ')
num = int(sen[1])
sen = int(sen[0])
lang1 = dict()
lang2 = dict()
for i in range(0, num):
	word = input().split(' ')
	lang1[word[0]] = word[1]
	lang2[word[1]] = word[0]
sentence = input().split(' ')
final = list()
for i in sentence:
	if i in lang1:
		if len(i) <= len(lang1[i]):
			final.append(i)
		else:
			final.append(lang1[i])
	elif i in lang1:
		if len(i) < len(lang2[i]):
			final.append(i)
		else:
			final.append(lang2[i])
s = ' '
final = s.join(final)
print(final)


(n, m) = map(int, input().split())
words1 = {}
words2 = {}
res = []
for i in range(m):
	(w1, w2) = map(str, input().split())
	words1[w1] = w2
	words2[w2] = w1
sntns = input()
sntns = list(sntns.split(' '))
for i in sntns:
	if i in words1.keys():
		if len(i) <= len(words1[i]):
			res.append(i)
		else:
			res.append(words1[i])
	elif i in words2.keys():
		if len(words2[i]) <= len(i):
			res.append(words2[i])
		else:
			res.append(i)
for i in res:
	print(i, end=' ')


(n, m) = map(int, input().split())
c = []
for i in range(m):
	a = list(map(str, input().split()))
	c.append(a)
z = list(map(str, input().split()))
l = []
for i in range(len(c)):
	l.append(c[i][0])
for i in range(len(z)):
	q = l.index(z[i])
	if len(z[i]) > len(c[q][1]):
		z[i] = c[q][1]
print(' '.join(z))


import sys, math
(n, m) = [int(i) for i in input().split(' ')]
a = dict()
for i in range(m):
	(x, y) = [i for i in input().split(' ')]
	a[x] = y
b = [i for i in input().split(' ')]
k = 0
for i in range(b.__len__()):
	s = b[i]
	if a.get(s):
		if len(a[s]) < len(s):
			if k == 0:
				k = 1
				print('', end='')
			else:
				print(' ', end='')
			print(a[b[i]], end='')
		else:
			if k == 0:
				k = 1
				print('', end='')
			else:
				print(' ', end='')
			print(b[i], end='')
	else:
		if k == 0:
			k = 1
			print('', end='')
		else:
			print(' ', end='')
		print(a[b[i]], end='')


(n, m) = map(int, input().split(' '))
ans = []
ref = []
res = []
for _ in range(m):
	(p, q) = input().split(' ')
	ref.append(p)
	if len(p) == len(q):
		ans.append(p)
	elif len(p) < len(q):
		ans.append(p)
	elif len(p) > len(q):
		ans.append(q)
s = list(input().split(' '))
for ii in range(n):
	res.append(ans[ref.index(s[ii])])
print(*res)


(lec, dic) = list(map(int, input().split()))
lang1 = dict()
for _ in range(dic):
	(f, s) = input().split()
	lang1[f] = s

def get_min(word):
	if len(word) <= len(lang1[word]):
		return word
	return lang1[word]
lecture = input().split()
ans = []
for word in lecture:
	ans.append(get_min(word))
print(*ans)


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
(a, b) = ml()
d = defaultdict(str)
for _ in range(b):
	(x, y) = input().split()
	if len(y) < len(x):
		d[x] = y
	else:
		d[x] = x
query = list(input().split())
for i in query:
	print(d[i], end=' ')


(n, m) = [int(i) for i in input().split()]
words = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		words[a] = a
	else:
		words[a] = b
notes = []
for word in input().split():
	notes.append(words[word])
print(' '.join(notes))


from math import ceil
numwords = input().split()
n = int(numwords[0])
m = int(numwords[1])
words = [input().split() for i in range(m)]
lan1 = [i[0] for i in words]
lan2 = [i[1] for i in words]
translate = input().split()
new = translate
k = 0
while k < m:
	if len(lan1[k]) > len(lan2[k]):
		new = list(map(lambda x: lan2[k] if x == lan1[k] else x, new))
	k += 1
exp = ' '.join((i for i in new))
print(exp)


(n, m) = map(int, input().split())
language_dict = dict()
output = []
for i in range(m):
	ls = list(input().split())
	language_dict[ls[0]] = ls[1]
text = list(input().split())
for i in range(n):
	value = len(language_dict[text[i]])
	if value >= len(text[i]):
		output.append(text[i])
	else:
		output.append(language_dict[text[i]])
for item in output:
	print(item, end=' ')


(x, y) = [int(i) for i in input().split()]
z = {}
for i in range(y):
	(a, b) = input().split()
	z.update({a: b})
for i in input().split():
	c = z[i]
	if len(c) < len(i):
		print(c, end=' ')
	else:
		print(i, end=' ')


(n, m) = map(int, input().split())
(a, b) = ([], [])
for i in range(m):
	ab = input().split()
	a.append(ab[0])
	b.append(ab[1])
c = input().split()
o = ' '.join([i if len(a[a.index(i)]) <= len(b[a.index(i)]) else b[a.index(i)] for i in c])
print(o)


(n, m) = [int(i) for i in input().split()]
d = {}
for i in range(m):
	(w0, w1) = input().split()
	d[w0] = w1
a = input().split()
for w in a:
	if len(w) > len(d[w]):
		print(d[w], end=' ')
	else:
		print(w, end=' ')


import sys
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
sys.setrecursionlimit(10 ** 7)
mod = 1000000007

def IOE():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, k) = map(int, sys.stdin.readline().split())
	d = dict()
	for i in range(k):
		s = list(map(str, sys.stdin.readline().split()))
		if s[0] not in d:
			d[s[0]] = min(s, key=lambda i: len(i))
	ss = list(map(str, sys.stdin.readline().split()))
	for i in range(n):
		ss[i] = d[ss[i]]
	print(*ss)
try:
	IOE()
except:
	pass
main()


(n, m) = list(map(int, input().split()))
a = []
b = ''
for i in range(m):
	(x, y) = input().split()
	a.append(x)
	a.append(y)
s = list(input().split())
for i in s:
	if len(i) > len(a[a.index(i) + 1]):
		b += a[a.index(i) + 1] + ' '
	else:
		b += i + ' '
print(b)


(n, m) = map(int, input().split())
words = []
for _ in range(m):
	words.append(input())
sentence = input().split()
(lang1, lang2) = ([], [])
for word in words:
	for i in range(len(word)):
		if word[i] == ' ':
			lang1.append(word[:i])
			lang2.append(word[i + 1:])
			break
to_speak = ''
for w in sentence:
	idx = lang1.index(w)
	to_speak += f'{[w, lang2[idx]][len(lang2[idx]) < len(w)]} '
print(to_speak)


def readline():
	return input()

class OptimalWriter:
	n = None
	m = None
	first_voc = None
	best_voc = None
	data = None

	def __init__(self, readline):
		self.read(readline)

	def voc_init(self):
		self.first_voc = [None] * self.m
		self.best_voc = [None] * self.m

	def read(self, readline):
		nn = readline().split(' ')
		self.n = int(nn[0])
		self.m = int(nn[1])
		self.voc_init()
		for i in range(self.m):
			s = readline().split(' ')
			self.first_voc[i] = s[0]
			if len(s[1]) < len(s[0]):
				self.best_voc[i] = s[1]
			else:
				self.best_voc[i] = s[0]
		self.data = readline().split(' ')

	def generate(self):
		result = ''
		for word in self.data:
			i = self.first_voc.index(word)
			result += ' ' + self.best_voc[i]
		return result[1:]

def main():
	writer = OptimalWriter(readline)
	print(writer.generate())
main()


numbers = list(input().split(' '))
dict1 = {}
for i in range(int(numbers[1])):
	chars = list(input().split(' '))
	dict1[chars[0]] = chars[1]
sent = list(input().split(' '))
st = ''
for i in sent:
	if len(i) > len(dict1[i]):
		st = st + ' ' + dict1[i]
	if len(i) < len(dict1[i]):
		st = st + ' ' + i
	if len(i) == len(dict1[i]):
		st = st + ' ' + i
print(st[1:])


line = input().split()
n = int(line[0])
m = int(line[1])
dict = {}
for i in range(m):
	line = input().split()
	dict[line[0]] = line[1]
lecture = input().split()
notes = []
for word in lecture:
	first = word
	second = dict[first]
	if len(first) <= len(second):
		notes.append(first)
	else:
		notes.append(second)
print(' '.join(notes))


import heapq as hp
import collections
import bisect
import math
import re

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def ml_unpack(n):
	return [int(input()) for i in range(n)]

def range_n():
	return range(int(input()))

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def getint():
	return int(input())

def setbits(x):
	count = 0
	while x:
		x = x & x - 1
		count += 1
	return count

def main():
	(n, m) = unpack()
	d = {}
	for i in range(m):
		(key, value) = input().split()
		d[key] = value
	lecture = input().split()
	ans = [word if len(word) <= len(d[word]) else d[word] for word in lecture]
	print(*ans)
main()


dict = {}
(a, b) = map(int, input().split())
for i in range(b):
	(x, y) = input().split()
	dict[x] = y
for i in input().split():
	print(min(i, dict[i], key=len), '', end='')


alle = input()
alle = list(map(int, alle.split()))
n = alle[0]
m = alle[1]
alle = []
dicc = []
a = []
lecture = []
output = []
for i in range(0, m):
	a = input()
	a = a.split(' ')
	a.append(0)
	dicc.append(a)
lecture = input()
lecture = list(lecture.split(' '))
j = 0
flag = False
for i in range(0, len(lecture)):
	while flag == False and j <= len(dicc):
		if lecture[i] == dicc[j][0]:
			flag = True
			if dicc[j][2] == 0:
				if len(dicc[j][0]) <= len(dicc[j][1]):
					output.append(dicc[j][0])
					dicc[j][2] = 1
				else:
					output.append(dicc[j][1])
					dicc[j][2] = 2
			elif dicc[j][2] == 1:
				output.append(dicc[j][0])
			else:
				output.append(dicc[j][1])
		j += 1
	flag = False
	j = 0
for i in range(0, len(output)):
	print(output[i], end=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	w = input().split()
	w = sorted(w, key=lambda x: len(x))
	dic[w[1]] = w[0]
words = input().split()
for i in words:
	if i in dic:
		print(dic[i], end=' ')
	else:
		print(i, end=' ')


def main():
	(n, m) = map(int, input().split())
	words = {}
	for i in range(m):
		(a, b) = input().split()
		if len(a) > len(b):
			words[a] = b
		elif len(a) < len(b):
			words[b] = a
	c = input().split()
	for (i, word) in enumerate(c):
		if word in words:
			c[i] = words[word]
	print(' '.join(c))
main()


(n, m) = [int(i) for i in input().split()]
mp = {}
for i in range(m):
	(a, b) = input().split()
	mp[a] = b
text = input().split()
answer = ''
for i in text:
	if len(i) <= len(mp[i]):
		answer += i + ' '
	else:
		answer += mp[i] + ' '
print(answer.rstrip())


(n, m) = map(int, input().split())
dic = dict()
for i in range(m):
	(l1, l2) = input().split()
	dic[l1] = l2
lecture = input()
lec_list = list(lecture.split(' '))
for i in lec_list:
	if len(i) > len(dic[i]):
		print(dic[i], end=' ')
	else:
		print(i, end=' ')


(a, b) = (list(map(int, input().split())), [])
for i in range(a[1]):
	c = input().split()
	if len(c[0]) <= len(c[1]):
		b.append([c[1], c[0]])
	else:
		b.append([c[0], c[1]])
c = dict(b)
for i in input().split():
	try:
		print(c[i], end=' ')
	except KeyError:
		print(i, end=' ')


(n, m) = map(int, input().split())
lst1 = []
lst2 = []
for i in range(0, m):
	(x, y) = map(str, input().split())
	lst1.append(x)
	lst2.append(y)
msg = list((str(m) for m in input().split()))[:n]
str1 = ''
for char in msg:
	i = lst1.index(char)
	if len(lst1[i]) > len(lst2[i]):
		str1 += lst2[i] + ' '
	else:
		str1 += lst1[i] + ' '
print(str1)


(n, m) = map(int, input().split())
pr = []
st = []
for i in range(m):
	(p, q) = map(str, input().split())
	pr.append(p)
	st.append(q)
out = list(map(str, input().split()))
for i in range(n):
	x = pr.index(out[i])
	if len(pr[x]) <= len(st[x]):
		print(pr[x], end=' ')
	else:
		print(st[x], end=' ')


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'.upper()
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	(n, m) = read()
	mp = {}
	for i in range(m):
		(a, b) = input().rstrip().split()
		if len(a) == len(b):
			mp[a] = a
			mp[b] = b
		elif len(a) < len(b):
			mp[a] = a
			mp[b] = a
		elif len(a) > len(b):
			mp[a] = b
			mp[b] = b
	c = input().rstrip().split()
	ans = []
	for x in c:
		ans.append(mp[x])
	print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(1):
	solve()


(n, m) = map(int, input().split())
l1 = []
l2 = []
for i in range(m):
	(a, b) = input().split()
	l1.append(a)
	l2.append(b)
nlist = input().split()
ans = ''
for i in range(n):
	if nlist[i] in l1:
		y = l1.index(nlist[i])
		t = l1[y] if len(l1[y]) <= len(l2[y]) else l2[y]
		ans += t
		ans += ' '
	else:
		y = l2.index(nlist[i])
		t = l1[y] if len(l1[y]) <= len(l2[y]) else l2[y]
		ans += t
		ans += ' '
print(ans)


(n, m) = map(int, input().split())
Dic = {}
for i in range(m):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		Dic[a] = [b, 1, a]
	else:
		Dic[a] = [b, 2, a]
Lec = list(map(str, input().split()))
for i in range(n):
	if Dic[Lec[i]][1] == 1:
		print(Dic[Lec[i]][2], end=' ')
	else:
		print(Dic[Lec[i]][0], end=' ')


def lecture(words, sentence):
	ans = []
	for i in sentence:
		val = min(len(words[i]), len(i))
		if len(i) == val:
			ans.append(i)
		else:
			ans.append(words[i])
	print(' '.join(ans))
(n, m) = list(map(int, input().rstrip().split()))
words = {}
for i in range(m):
	x = input().rstrip().split()
	words[x[0]] = x[1]
sentence = input().rstrip().split()
lecture(words, sentence)


(n, m) = [int(i) for i in input().split()]
a = []
b = []
for _ in range(m):
	l = input().split()
	a.append(l[0])
	b.append(l[1])
s = input().split()
z = []
for i in s:
	x = a.index(i)
	if len(a[x]) == len(b[x]):
		z.append(a[x])
	elif len(a[x]) > len(b[x]):
		z.append(b[x])
	elif len(a[x]) < len(b[x]):
		z.append(a[x])
print(' '.join(z))


import sys

def compare(a, b):
	if len(a) <= len(b):
		return a
	return b

def f(b, a):
	c = []
	for i in range(len(b)):
		c.append(compare(a[a.index(b[i])], a[a.index(b[i]) + 1]))
	return c
input = sys.stdin.read()
data = list(map(str, input.split()))
n = int(data[0])
m = int(data[1])
a = list(map(str, data[2:2 * m + 2]))
b = list(data[2 * m + 2:])
ans = f(b, a)
print(*ans)


numbers = list(map(int, input().split()))
dictionary = []
for i in range(0, numbers[1]):
	words = input().split()
	dictionary.append(1 if len(words[0]) <= len(words[1]) else 2)
	dictionary.append(words[0])
	dictionary.append(words[1])
lecture = input().split()
result = ''
for i in range(0, numbers[0]):
	indexInDic = dictionary.index(lecture[i])
	numberIndex = indexInDic - indexInDic % 3
	number = dictionary[numberIndex]
	result += dictionary[numberIndex + number] + ' '
print(result.strip())


def answer(n, m, d, c):
	for i in range(n):
		if len(c[i]) > len(d[c[i]]):
			c[i] = d[c[i]]
	return c
(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
c = input().split()
print(*answer(n, m, d, c))


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
dict = {}
(n, m) = rinput()
for _ in range(m):
	(l1, l2) = tinput()
	if len(l1) < len(l2):
		smaller = l1
	elif len(l1) == len(l2):
		smaller = l1
	else:
		smaller = l2
	dict[l1] = smaller
	dict[l2] = smaller
speech = list(tinput())
for word in speech:
	print(dict[word], end=' ')


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline().strip())
(n, m) = get_int_list()
d = {}
for i in range(m):
	(a, b) = get_string().split()
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
string = get_string().split()
res = []
for i in string:
	res.append(d[i])
print(' '.join(res))


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	(n, k) = vars()
	m = {}
	for i in range(k):
		(s1, s2) = input().split()
		m[s1] = s2
	words = list(input().split())
	ans = ''
	for w in words:
		if len(w) <= len(m[w]):
			ans += w + ' '
		else:
			ans += m[w] + ' '
	print(ans.strip())
t = 1
for _ in range(t):
	main()


lang = {}
(n, m) = map(int, input().split())
for i in range(m):
	arr = list(map(str, input().split()))
	lang.update({arr[0]: arr[1]})
str1 = list(map(str, input().split()))
for i in range(n):
	if str1[i] in lang:
		x = str1[i]
		y = lang[x]
		if len(x) <= len(y):
			print(x, end=' ')
		else:
			print(y, end=' ')
	else:
		y = str1[i]
		for k in lang:
			if lang[k] == y:
				x = lang[k]
				break
			else:
				continue
		if len(x) < len(y):
			print(x, end=' ')
		else:
			print(y, end=' ')


(a, b) = map(int, input().split(' '))
d = {}
for k in range(b):
	(a, b) = input().split(' ')
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
for k in input().split(' '):
	print(d[k], end=' ')


(n, m) = map(int, input().split())
q = []
w = []
ans = []
for i in range(m):
	(a, b) = map(str, input().split())
	q.append(a)
	w.append(b)
ans = list(map(str, input().split()))
for i in range(n):
	if len(q[q.index(ans[i])]) > len(w[q.index(ans[i])]):
		ans[i] = w[q.index(ans[i])]
print(*ans)


(n, m) = map(int, input().split())
l_first = []
l_second = []
for i in range(m):
	(first, second) = input().split()
	l_first.append(first)
	l_second.append(second)
l = list(input().split())
s = ''
for i in range(n):
	if len(l[i]) > len(l_second[l_first.index(l[i])]):
		s = s + l_second[l_first.index(l[i])] + ' '
	else:
		s = s + l[i] + ' '
print(s)


(lec, w) = map(int, input().split())
l = {}
for t in range(w):
	p = list(map(str, input().split()))
	l[p[0]] = p[1]
main = list(map(str, input().split()))
for t in main:
	if len(l[t]) < len(t):
		print(l[t], end=' ')
	else:
		print(t, end=' ')
print('\r')


(n, m) = map(int, input().split(' '))
mp = {}
for i in range(m):
	s = input().split(' ')
	(mp[s[0]], mp[s[1]]) = (min(s, key=len), min(s, key=len))
print(' '.join((mp[i] for i in input().split(' '))))


(n, m) = eval(input().replace(' ', ','))
li1 = []
li2 = []
dic = {}
for i in range(m):
	li1.append(input().split(' '))
	if len(li1[i][0]) > len(li1[i][1]):
		dic[li1[i][0]] = li1[i][1]
	else:
		dic[li1[i][0]] = li1[i][0]
li2 = input().split(' ')
for i in range(n):
	li2[i] = dic[li2[i]]
print(' '.join(li2))


(n, m) = [int(i) for i in input().split()]
a = {}
for i in range(m):
	(aa, bb) = input().split()
	if len(bb) < len(aa):
		a[aa] = bb
	else:
		a[aa] = aa
print(' '.join([a[i] for i in input().split()]))


(n, m) = map(int, input().split())
translate = {}
for i in range(m):
	(first, second) = input().split()
	if len(first) <= len(second):
		translate[first] = first
	else:
		translate[first] = second
words = list(input().split())
answer = ''
for word in words:
	answer += translate[word] + ' '
print(answer)


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
language = {}
for i in range(m):
	words = list(map(str, input().strip().split(' ')))
	language.setdefault(words[0], words[1])
lecture = list(map(str, input().strip().split(' ')))
i = 0
while i < n:
	if len(lecture[i]) > len(language[lecture[i]]):
		lecture[i] = language[lecture[i]]
	i += 1
print(' '.join(lecture))


(n, m) = list(map(int, input().split()))
l = []
for i in range(m):
	l.append(list(input().split()))
p = list(input().split())
d = {}
for i in range(m):
	d[l[i][0]] = l[i][1]
s = ''
for i in range(n):
	if len(d[p[i]]) >= len(p[i]):
		s = s + p[i] + ' '
	else:
		s = s + d[p[i]] + ' '
print(s[0:len(s) - 1])


(n, m) = map(int, input().split())
a_list = []
b_list = []
for i in range(m):
	(a, b) = input().split()
	a_list.append(a)
	b_list.append(b)
lect = input().split()
ans = []
for i in lect:
	if i in a_list:
		pos = a_list.index(i)
		j = b_list[pos]
		if len(i) > len(j):
			ans.append(j)
		else:
			ans.append(i)
	else:
		pos = b_list.index(i)
		j = a_list[pos]
		if len(i) > len(j):
			ans.append(j)
		else:
			ans.append(i)
print(*ans)


(n, m) = list(map(int, input().split()))
(first, second) = ([], [])
for i in range(m):
	(a, b) = input().split()
	first.append(a)
	second.append(b)
lecture = input().split()
(firstlen, secondlen) = ([], [])
for i in range(m):
	firstlen.append(len(first[i]))
	secondlen.append(len(second[i]))
for word in lecture:
	temp = first.index(word)
	if firstlen[temp] <= secondlen[temp]:
		print(first[temp], end=' ')
	else:
		print(second[temp], end=' ')


(n, m) = map(int, input().split())
words = []
for i in range(m):
	words.append(sorted(input().split(), key=len))
sol = f' {input()} '
for word in words:
	while sol.count(f' {word[1]} '):
		sol = sol.replace(f' {word[1]} ', f' {word[0]} ', 1)
print(sol.strip())


(n, m) = map(int, input().split())
words = []
notes = []
for i in range(m):
	(z, x) = map(str, input().split())
	words.append(z)
	words.append(x)
letter = [x for x in input().split()]
for i in range(len(letter)):
	temp = words.index(letter[i])
	if temp % 2 == 0:
		if len(words[temp]) > len(words[temp + 1]):
			notes.append(words[temp + 1])
		else:
			notes.append(words[temp])
	elif len(words[temp]) < len(words[temp - 1]):
		notes.append(words[temp])
	else:
		notes.append(words[temp - 1])
print(*notes)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(r1, r2) = input().split()
	if len(r2) < len(r1):
		d[r1] = r2
	else:
		d[r1] = r1
print(*[d[i] for i in input().split()])


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	s = input()
	l = s.split(' ')
	key = l[0]
	value = l[1]
	dic.update({key: value})
str = input()
l = str.split(' ')
res = ''
for i in l:
	if i in dic:
		if len(i) <= len(dic[i]):
			res = res + i + ' '
		else:
			res = res + dic[i] + ' '
print(res)


(n, m) = map(int, input().split())
A = [0] * m
B = [0] * m
for i in range(m):
	(A[i], B[i]) = input().split()
a = input()
C = [0] * n
for i in range(n - 1):
	num = a.find(' ')
	C[i] = a[:num]
	a = a[num + 1:]
C[n - 1] = a
for i in range(n):
	if C[i] in A:
		b = A.index(C[i])
		if len(A[b]) <= len(B[b]):
			print(A[b], end=' ')
		else:
			print(B[b], end=' ')
	else:
		b = B.index(C[i])
		if len(A[b]) <= len(B[b]):
			print(A[b], end=' ')
		else:
			print(B[b], end=' ')


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	l = input().split()
	d[l[0]] = l[1]
p = input().split()
for i in range(n):
	if len(p[i]) <= len(d[p[i]]):
		print(p[i], end=' ')
	else:
		print(d[p[i]], end=' ')


l = input().split()
n = int(l[0])
m = int(l[1])
x = []
y = []
for i in range(m):
	inp = input().split()
	x.append(inp[0])
	if len(inp[1]) < len(inp[0]):
		y.append(inp[1])
	else:
		y.append(inp[0])
prof = input().split()
for i in range(n):
	prof[i] = y[x.index(prof[i])]
s = prof[0]
for i in range(1, n):
	s += ' ' + prof[i]
print(s)


import sys
(n, m) = [int(x) for x in sys.stdin.readline().split()]
d = dict()
for i in range(m):
	(s1, s2) = sys.stdin.readline().split()
	if len(s1) > len(s2):
		d[s1] = s2
	else:
		d[s2] = s1
res = []
for i in sys.stdin.readline().split():
	if i in d:
		res.append(d[i])
	else:
		res.append(i)
print(' '.join(res))


str = input()
(teach, num) = str.split()
teach = int(teach)
num = int(num)
f = {}
for i in range(num):
	str = input()
	(index, f[index]) = str.split()
ans = []
str = input()
b = str.split()
for i in range(teach):
	if len(f[b[i]]) < len(b[i]):
		ans.append(f[b[i]])
	else:
		ans.append(b[i])
print(' '.join(ans))


(n, m) = map(int, input().split())
result2 = []
result1 = []
for i in range(m):
	inp = input().split()
	result1.append(inp[0])
	if len(inp[1]) < len(inp[0]):
		result2.append(inp[1])
	else:
		result2.append(inp[0])
ql = list(input().split())
for i in range(len(ql)):
	index = result1.index(ql[i])
	ql[i] = result2[index]
print(' '.join(ql))


(last, rows) = [int(a) for a in input().split()]
Rows = [0] * rows
Dict = {}
for x in range(rows):
	Pair = input().split()
	if len(Pair[0]) > len(Pair[1]):
		Min = Pair[1]
	else:
		Min = Pair[0]
	Dict[Pair[0]] = Min
	Dict[Pair[1]] = Min
Words = input().split()
for word in Words:
	print(Dict[word], end=' ')


(n, k) = map(int, input().split())
lang1 = []
lang2 = []
for i in range(k):
	str1 = input()
	(a, b) = str1.split(' ')
	lang1.append(a)
	lang2.append(b)
str1 = input()
prof = list(str1.split(' '))
notes = []
for i in range(n):
	word = prof[i]
	if lang1.count(word) == 1:
		index = lang1.index(word)
		if len(lang1[index]) > len(lang2[index]):
			print(lang2[index], end=' ')
		elif len(lang1[index]) == len(lang2[index]):
			print(lang1[index], end=' ')
		elif len(lang1[index]) < len(lang2[index]):
			print(lang1[index], end=' ')
	elif lang2.count(word) == 1:
		index = lang2.index(word)
		if len(lang1[index]) > len(lang2[index]):
			print(lang2[index], end=' ')
		elif len(lang1[index]) == len(lang2[index]):
			print(lang1[index], end=' ')
		elif len(lang1[index]) < len(lang2[index]):
			print(lang1[index], end=' ')
print('\n')


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	text = input().split()
	if len(text[0]) <= len(text[1]):
		d[text[0]] = text[0]
	else:
		d[text[0]] = text[1]
num = list(map(str, input().split()))
for i in range(0, n):
	print(d[num[i]], end=' ')


n = input().split(' ')
str = ''
new = []
b = {}
for i in range(int(n[1])):
	n1 = input().split(' ')
	b[n1[0]] = n1[1]
str = input().split(' ')
for k in str:
	if len(k) <= len(b[k]):
		new.append(k)
	else:
		new.append(b[k])
new1 = ' '.join(new)
print(new1)


(len_speech, num_words) = map(int, input().split())
words = {}
for x in range(num_words):
	(in1, in2) = map(str, input().split())
	words[in1] = in2
speech = list(input().split())
for x in range(len_speech - 1):
	if len(speech[x]) > len(words[speech[x]]):
		print(words[speech[x]], end=' ')
	else:
		print(speech[x], end=' ')
if len(speech[len_speech - 1]) > len(words[speech[len_speech - 1]]):
	print(words[speech[len_speech - 1]], end='')
else:
	print(speech[len_speech - 1], end='')


(a, b) = map(int, input().split())
total = []
ans = ''
for i in range(b):
	(z, x) = input().split()
	if len(z) == len(x):
		total.append([z, x])
	elif len(z) < len(x):
		total.append([z, x])
	else:
		total.append([x, z])
word = input()
for i in word.split():
	for x in total:
		if i in x:
			ans += x[0] + ' '
print(ans)


n = list(map(int, input().split()))
lan1 = []
lan2 = []
for i in range(n[1]):
	t = input().split()
	lan1.append(t[0])
	lan2.append(t[1])
str = input().split()
for i in str:
	t = lan1.index(i)
	if len(lan1[t]) <= len(lan2[t]):
		print(lan1[t], end='')
	else:
		print(lan2[t], end='')
	if not str.index(i) == len(str) - 1:
		print(' ', end='')


(n, k) = map(int, input().split())
d = {}
for _ in range(k):
	(a, b) = map(str, input().split())
	if len(a) <= len(b):
		d[a] = a
	else:
		d[a] = b
s = list(map(str, input().split()))
w = ''
for i in range(n):
	w += d[s[i]] + ' '
print(w)


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	(s1, s2) = input().split()
	dic[s1] = s2
sample = input().split()
for i in sample:
	s3 = dic[i]
	if len(i) <= len(s3):
		print(i, end=' ')
	else:
		print(s3, end=' ')


(n, m) = [int(x) for x in input().split()]
language = {}
for i in range(m):
	word = [x for x in input().split()]
	if len(word[0]) <= len(word[1]):
		language[word[0]] = word[0]
	else:
		language[word[0]] = word[1]
lecture = [x for x in input().split()]
note = []
for i in lecture:
	note.append(language[i])
print(' '.join(note))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	d[a] = b
out = ''
for i in input().split():
	if len(i) <= len(d[i]):
		out += i + ' '
	elif len(i) > len(d[i]):
		out += d[i] + ' '
print(out.rstrip())


__author__ = 'Rakshak.R.Hegde'
(n, m) = map(int, input().split())
trans = dict()
for i in range(m):
	(x, y) = input().split()
	trans[x] = y
lect = input().split()
ans = ''
for w in lect:
	ans += min(w, trans[w], key=lambda x: len(x)) + ' '
print(ans)


a = [int(i) for i in input().split()]
dic = {}
for i in range(a[1]):
	c = input().split()
	dic[c[0]] = c[1]
c = input().split()
letter = ''
for i in c:
	if len(i) > len(dic[i]):
		letter += dic[i] + ' '
	else:
		letter += i + ' '
print(letter)


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		d[a] = b
	elif len(a) < len(b):
		d[b] = a
for i in input().split():
	print(d.get(i, i), end=' ')


nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
(l1, l2) = ([], [])
shorter = []
for i in range(m):
	(a1, a2) = input().split()
	l1.append(a1)
	l2.append(a2)
	mini = a2 if len(a1) > len(a2) else a1
	shorter.append(mini)
text_words = list(input().split())
for word in text_words:
	if word in l1:
		print(shorter[l1.index(word)], end=' ')
	else:
		print(shorter[l2.index(word)], end=' ')


(n, m) = tuple([int(x) for x in input().split()])
d = {}
for x in range(0, m):
	t = tuple([x for x in input().split()])
	d[t[0]] = t[1]
s = input()
l = s.split()
o = ''
for x in l:
	if len(x) > len(d[x]):
		o += ' ' + d[x]
	else:
		o += ' ' + x
print(o.strip())


(n, m) = [int(i) for i in input().split()]
lst = []
while m:
	m -= 1
	s = input()
	for i in s.split():
		lst.append(i)
s = input()
lst2 = []
for i in s.split():
	lst2.append(i)
s = ''
for i in range(n):
	x = lst.index(lst2[i])
	if len(lst[x]) <= len(lst[x + 1]):
		s += lst[x] + ' '
	else:
		s += lst[x + 1] + ' '
print(s)


(n, m) = map(int, input().split())
a = {}
for i in range(m):
	(n, m) = input().split()
	a[n] = m
st = input()
st1 = ''
for i in st.split():
	if len(a[i]) < len(i):
		st1 += a[i] + ' '
	else:
		st1 += i + ' '
print(st1)


[a, b] = map(int, input().split())
d = {}
for i in range(b):
	[s1, s2] = map(str, input().split())
	d.update({s1: s2})
s = list(map(str, input().split()))
for i in range(a):
	if len(s[i]) > len(d[s[i]]):
		s[i] = d[s[i]]
print(' '.join(s))


(n, m) = map(int, input().split())
d = {}
for i in range(m):
	(w, v) = input().split()
	d[w] = v
ls = input().split()
for i in range(len(ls)):
	if len(d[ls[i]]) < len(ls[i]):
		ls[i] = d[ls[i]]
print(' '.join(ls))


one = two = i = str()
(n, m) = [int(i) for i in input('').split(' ')]
word = dict()
j = int()
for j in range(m):
	(one, two) = input('').split(' ')
	if len(one) <= len(two):
		word[one] = one
	else:
		word[one] = two
for i in input('').split(' '):
	print(word[i], end=' ')


a = {}
(n, m) = map(int, input().split())
for i in range(m):
	(x, y) = map(str, input().split())
	if len(x) > len(y):
		a[x] = y
	else:
		a[x] = x
b = [str(x) for x in input().split()]
for j in b:
	print(a[j], end=' ')
print('\n')


(a, b) = map(int, input().split())
m = {}
for i in range(b):
	(x, y) = map(str, input().split())
	if len(x) == len(y):
		continue
	elif len(x) < len(y):
		m[y] = x
	else:
		m[x] = y
arr = list(map(str, input().split()))
for i in range(a):
	if arr[i] in m:
		arr[i] = m[arr[i]]
	else:
		continue
print(*arr)


(n, m) = map(int, input().split())
a = []
for i in range(m):
	b = input().split()
	if len(b[1]) < len(b[0]):
		b.reverse()
	a += b
s = input().split()
d = ''
for i in s:
	d += a[a.index(i) // 2 * 2] + ' '
print(d)


(n, m) = input().split()
n = int(n)
m = int(m)
dictt = []
for i in range(m):
	(a, b) = input().split()
	dictt.append(a)
	dictt.append(b)
a = input().split()
for i in a:
	pos = dictt.index(i) // 2
	if len(dictt[2 * pos]) <= len(dictt[2 * pos + 1]):
		print(dictt[2 * pos], end=' ')
	else:
		print(dictt[2 * pos + 1], end=' ')


is_debug = False
(n, m) = [int(x) for x in input().split()]
d = {}
for i in range(0, m):
	(k, v) = input().split()
	v = k if len(k) <= len(v) else v
	d[k] = v
print(f'd={d}') if is_debug else ''
s = input().split()
l = []
for c in s:
	l.append(d[c])
print(f"{' '.join(l)}")


size = list(map(int, input().split()))
words = {}
for i in range(size[1]):
	temp = input().split()
	if len(temp[0]) > len(temp[1]):
		words[temp[0]] = temp[1]
	else:
		words[temp[0]] = temp[0]
lec_words = input().split()
fi = ''
for i in range(len(lec_words)):
	if i != len(lec_words) - 1:
		fi = fi + f'{words[lec_words[i]]} '
	else:
		fi = fi + f'{words[lec_words[i]]}'
print(fi)


(n, m) = map(int, input().split())
(firstLanguage, secondLanguage) = ([], [])
for i in range(m):
	line = input().split()
	firstLanguage.append(line[0])
	secondLanguage.append(line[1])
s = input().split()
for i in s:
	idx = 0
	if firstLanguage.index(i) < 0:
		idx = secondLanguage.index(i)
	else:
		idx = firstLanguage.index(i)
	if len(firstLanguage[idx]) <= len(secondLanguage[idx]):
		print(firstLanguage[idx], end=' ')
	else:
		print(secondLanguage[idx], end=' ')


(n, m) = tuple(map(int, input().split()))
dic = {}
for k in range(m):
	(a, b) = tuple(input().split())
	if len(a) <= len(b):
		dic[a] = a
		dic[b] = a
	else:
		dic[a] = b
		dic[b] = b
print(' '.join(list(map(lambda x: dic[x], input().split()))))


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)
a = {}
(n, m) = isp()
while m > 0:
	(s1, s2) = map(str, input().split())
	a[s1] = s2
	m -= 1
s = list(map(str, input().split()))
for i in s:
	if len(i) <= len(a[i]):
		print(i, end=' ')
	else:
		print(a[i], end=' ')


(n, m) = map(int, input().split())
f = []
s = []
for i in range(m):
	z = input().split()
	f.append(z[0])
	s.append(z[1])
z = input().split()
t = ''
for x in z:
	i = f.index(x)
	if len(s[i]) < len(f[i]):
		t += s[i] + ' '
	else:
		t += f[i] + ' '
print(t)


(n, k) = map(int, input().split())
l = []
r = []
for i in range(k):
	x = list(map(str, input().split()))
	l.append([x[0], len(x[0])])
	r.append([x[1], len(x[1])])
y = list(map(str, input().split()))
h = []
for i in y:
	k = l.index([i, len(i)])
	if l[k][1] > r[k][1]:
		h.append(r[k][0])
	else:
		h.append(l[k][0])
print(' '.join(h))


def main():
	from sys import stdin, stdout
	(n, m) = map(int, stdin.readline().split())
	mydic = {}
	for _ in range(m):
		(a, b) = map(str, stdin.readline().strip().split())
		mydic[a] = b
	for k in stdin.readline().strip().split():
		if len(mydic[k]) < len(k):
			stdout.write(mydic[k] + ' ')
		else:
			stdout.write(k + ' ')
main()


(m, n) = map(int, input().split())
x = []
y = []
for i in range(n):
	(p, q) = input().split()
	x.append(p)
	y.append(q)
z = list(input().split())
for i in z:
	if i in x:
		a = i
		b = y[x.index(i)]
	else:
		b = i
		a = x[y.index(i)]
	if len(a) <= len(b):
		print(a, end=' ')
	else:
		print(b, end=' ')


inp = input().split()
n = int(inp[0])
m = int(inp[1])
l = {}
for _ in range(m):
	st = input().split()
	l[st[0]] = st[1]
lec = input().split()
for x in lec:
	l2 = l[x]
	if len(l2) < len(x):
		print(l2, end=' ')
	else:
		print(x, end=' ')


(a, b) = map(int, input().split())
d = {}
for i in range(b):
	(j, k) = map(str, input().split())
	d[j] = k
k = input().split()
l = []
for i in k:
	if len(d[i]) < len(i):
		l.append(d[i])
	else:
		l.append(i)
print(*l)


def read_input():
	(n, m) = [int(i) for i in input().split(' ')]
	rows = [input() for _ in range(m)]
	lecture = [c for c in input().split(' ')]
	return (n, m, rows, lecture)

def do_lecture(n, m, rows, lecture):
	dic = {}
	for row in rows:
		(first, second) = row.split(' ')
		dic[first] = first if min(len(first), len(second)) == len(first) else second
	output = []
	for word in lecture:
		output.append(dic[word])
	return output

def main():
	(n, m, rows, lecture) = read_input()
	print(' '.join(do_lecture(n, m, rows, lecture)))
main()


(words_in_lecture, words_in_language) = [int(a) for a in input().strip().split()]
lang1_to_2 = dict()
lang2_to_1 = dict()
for _ in range(words_in_language):
	(lang1, lang2) = [a for a in input().strip().split()]
	lang1_to_2[lang1] = lang2
	lang2_to_1[lang2] = lang1
lecture_content = [a for a in input().strip().split()]
translated = []
for word in lecture_content:
	if word in lang1_to_2.keys():
		if len(word) <= len(lang1_to_2[word]):
			translated.append(word)
		else:
			translated.append(lang1_to_2[word])
	elif len(word) < len(lang2_to_1[word]):
		translated.append(word)
	else:
		translated.append(lang2_to_1[word])
print(' '.join(translated))


(n, m) = list(map(int, input().split()))
words = []
for i in range(m):
	(a, b) = input().split()
	words.append(a)
	words.append(b)
s = input()
for i in s.split():
	ind = words.index(i)
	if ind % 2 == 0:
		lan1 = words[ind]
		lan2 = words[ind + 1]
	else:
		lan1 = words[ind]
		lan2 = words[ind - 1]
	if len(lan1) <= len(lan2):
		print(lan1, end=' ')
	else:
		print(lan2, end=' ')


(n, m) = map(int, input().split())
d = {}
for m0 in range(m):
	(a, b) = input().split()
	if len(a) <= len(b):
		d[a] = a
		d[b] = a
	else:
		d[a] = b
		d[b] = b
c = input().split()
l = [d[i] for i in c]
print(' '.join(l))


(a, b) = map(int, input().split())
(fl, sl) = ([], [])
for _ in range(b):
	(c, d) = map(str, input().split())
	fl.append(c)
	sl.append(d)
f = list(map(str, input().split()))
ans = []
for _ in range(len(f)):
	ind = fl.index(f[_])
	if len(f[_]) <= len(sl[ind]):
		ans.append(f[_])
	else:
		ans.append(sl[ind])
print(' '.join(ans))


(n, m) = map(int, input().split())
D = {}
for i in range(m):
	(a, b) = input().split()
	if len(a) > len(b):
		D.update({a: b})
s = input().split()
S = str()
for i in s:
	if i in D.keys():
		S += D[i] + ' '
	else:
		S += i + ' '
print(S.rstrip())


T = input().split()
n = int(T[0])
m = int(T[1])
Relation = dict()
for i in range(m):
	words = input().split(sep=' ')
	lang1 = words[0]
	lang2 = words[1]
	if len(lang1) > len(lang2):
		Relation.update({lang1: lang2})
	else:
		Relation.update({lang2: lang1})
lecture = input().split(sep=' ')
ans = []
for word in lecture:
	if Relation.get(word):
		ans.append(Relation.get(word))
	else:
		ans.append(word)
print(*ans)


(n, m) = map(int, input().split(' '))
f = [0] * n
d = {}
for i in range(m):
	(a, b) = input().split(' ')
	d[a] = b
s = input().split(' ')
for (i, w) in enumerate(s):
	f[i] = w if len(w) <= len(d[w]) else d[w]
print(' '.join(f))


(n, m) = map(int, input().split())
hash = {}
for i in range(m):
	(k1, k2) = map(str, input().split())
	hash[k1] = [k2, 1]
	hash[k2] = [k1, 2]
z = input()
ans = z.split()
st = []
for i in ans:
	if len(hash[i][0]) < len(i):
		st.append(hash[i][0])
	elif len(hash[i][0]) > len(i):
		st.append(i)
	elif len(hash[i][0]) == len(i):
		if hash[i][1] == 1:
			st.append(i)
		else:
			st.append(hash[i][0])
for i in st:
	print(i, end=' ')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	x = input().split()
	a.append(x[0])
	b.append(x[1])
s = input().split()
l = []
for j in range(len(s)):
	l.append(s[j])
ans = ''
for i in l:
	if i in a:
		ind = a.index(i)
	else:
		ind = b.index(i)
	q = len(a[ind])
	w = len(b[ind])
	if w < q:
		ans += b[ind]
		ans += ' '
	else:
		ans += a[ind]
		ans += ' '
print(ans)


def solve_the_problem():
	(n, m) = [int(x) for x in input().split(' ')]
	dictionary = {}
	for i in range(0, m):
		(word, translation) = input().split(' ')
		dictionary[word] = translation
	teachers_speech = input().split(' ')
	result = ''
	for word in teachers_speech:
		if len(word) <= len(dictionary[word]):
			result += word
			result += ' '
		else:
			result += dictionary[word]
			result += ' '
	print(result[:-1])
solve_the_problem()


(n, m) = input().split()
n = int(n)
m = int(m)
list1 = []
list2 = []
sent = []
answer = []
for i in range(0, m):
	(x, y) = input().split()
	list1.append(x)
	list2.append(y)
sent = input().split()
for i in range(0, len(sent)):
	temp = sent[i]
	ind = list1.index(temp)
	if len(list1[ind]) <= len(list2[ind]):
		answer.append(list1[ind])
	else:
		answer.append(list2[ind])
print(*answer)


(n, m) = map(int, input().split())
dicti = {}
for i in range(m):
	(first, second) = map(str, input().split())
	if len(first) <= len(second):
		dicti[first] = first
		dicti[second] = first
	else:
		dicti[first] = second
		dicti[second] = second
sentence = list(map(str, input().split()))
for i in range(len(sentence)):
	sentence[i] = dicti[sentence[i]]
print(' '.join(sentence))


([n, m], word_pairs) = ([int(i) for i in input().split()], [])
for i in range(m):
	word_pairs.append(input().split())
sentence = input().split()
word_map = {}
for pair in word_pairs:
	word = pair[0] if len(pair[0]) <= len(pair[1]) else pair[1]
	word_map[pair[0]] = word
	word_map[pair[1]] = word
for (i, word) in enumerate(sentence):
	sentence[i] = word_map[word]
print(' '.join([x for x in sentence]))


def get_shorter(ci, _a, _b):
	_i = 0
	while ci != _a[_i]:
		_i += 1
	return _a[_i] if len(_a[_i]) <= len(_b[_i]) else _b[_i]
(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(ai, bi) = input().split()
	a.append(ai)
	b.append(bi)
c = input().split()
result = []
for i in range(n):
	result.append(get_shorter(c[i], a, b))
print(*result, sep=' ')


(n, m) = map(int, input().split())
dic = {}
for i in range(m):
	a = input().split()
	if len(a[1]) < len(a[0]):
		dic.update({a[0]: a[1]})
lec = input().split()
output = []
for i in lec:
	if i in dic:
		output.append(dic[i])
	else:
		output.append(i)
print(' '.join(output))


(a, b) = map(int, input().split())
z = {}
for x in range(b):
	(c, d) = input().split()
	if len(d) < len(c):
		z[c] = d
	else:
		z[c] = c
l = list(input().split())
for x in range(a):
	l[x] = z[l[x]]
print(*l)


(n, m) = map(int, input().split())
l1 = []
l2 = []
for i in range(m):
	(s1, s2) = map(str, input().split())
	l1.append(s1)
	l2.append(s2)
l3 = list(map(str, input().split()))
fs = ''
(c, d, e) = (0, 0, 0)
f = 0
for i in l3:
	if i in l1:
		e = l1.index(i)
		d = len(l2[e])
		c = len(i)
		if c <= d:
			fs += i
			fs += ' '
		else:
			fs += l2[e]
			fs += ' '
	else:
		e = l2.index(i)
		c = len(l1[e])
		d = len(i)
		if c <= d:
			fs += l1[e]
			fs += ' '
		else:
			fs += i
			fs += ' '
print(fs)


dictionarie = {}
(n, m) = map(int, input().split())
for i in range(m):
	(lang_1, lang_2) = input().split()
	if len(lang_1) <= len(lang_2):
		dictionarie[lang_2] = lang_1
	else:
		dictionarie[lang_1] = lang_2
lecture = input().split()
for i in range(n):
	if lecture[i] in dictionarie.keys():
		lecture[i] = dictionarie[lecture[i]]
print(' '.join(lecture))


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, m) = mp()
	x = []
	p = []
	for i in range(m):
		s = input().split()
		x.append(s)
		if len(s[0]) <= len(s[1]):
			p.append(s[0])
		else:
			p.append(s[1])
	l = input().split()
	y = []
	for i in l:
		if i in p:
			y.append(i)
		else:
			for j in range(m):
				if i in x[j]:
					if len(x[j][0]) <= len(x[j][1]):
						y.append(x[j][0])
					else:
						y.append(x[j][1])
	print(*y)
solve()


(n, m) = input().split()
a = []
b = []
for i in range(int(m)):
	(s, k) = input().split()
	a.append(s)
	b.append(k)
w = list(input().split(' '))
for i in w:
	if i in a:
		ind = a.index(i)
	else:
		ind = b.index(i)
	if len(b[ind]) > len(a[ind]) or len(b[ind]) == len(a[ind]):
		print(a[ind], end=' ')
	else:
		print(b[ind], end=' ')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(m):
	(a1, b1) = input().split()
	a.append(a1)
	b.append(b1)
c = list(input().split())
ans = ''
for i in range(n):
	c1 = a.index(c[i])
	ans += min(a[c1], b[c1], key=len)
	ans += ' '
print(ans)


n = input().split()
k = []
k.append('0')
for i in range(0, int(n[1])):
	temp = input().split()
	k.append(temp[0])
	k.append(temp[1])
lek = input().split()
st = ''
for i in lek:
	num = k.index(i)
	temp1 = 0
	temp2 = 0
	if num % 2 == 1:
		temp1 = k[num]
		temp2 = k[num + 1]
	else:
		temp1 = k[num - 1]
		temp2 = k[num]
	if len(temp1) > len(temp2):
		st += temp2 + ' '
	elif len(temp2) > len(temp1):
		st += temp1 + ' '
	else:
		st += temp1 + ' '
print(st.strip())


first_line = list(map(int, input().split()))
my_dict = dict()
for i in range(first_line[1]):
	two_words = list(input().split())
	if len(two_words[0]) <= len(two_words[1]):
		my_dict[two_words[0]] = two_words[0]
		my_dict[two_words[1]] = two_words[0]
	else:
		my_dict[two_words[0]] = two_words[1]
		my_dict[two_words[1]] = two_words[1]
output = list()
for w in list(input().split()):
	output.append(my_dict[w])
print(*output)


d = {}
(n, m) = list(map(int, input().split()))
for _ in range(m):
	(a, b) = input().split()
	if len(b) == max(len(a), len(b)):
		d[b] = a
	else:
		d[a] = b
c = input().split()
for s in c:
	print(d[s] if s in d else s, end=' ')


(n, m) = [int(i) for i in input().split()]
dic = {}
for i in range(m):
	(a, b) = [j for j in input().split()]
	dic[a] = b
professorL = [i for i in input().split()]
lecture = [''] * n
for i in range(n):
	s = professorL[i]
	la = len(s)
	lb = len(dic[s])
	if la <= lb:
		lecture[i] = s
	else:
		lecture[i] = dic[s]
print(*lecture)


(n, m) = map(int, input().split())
arr_1 = []
arr_2 = []
for _ in range(m):
	(a, b) = input().split()
	arr_1.append(a)
	arr_2.append(b)
sentence = list(input().split())
ans = []
notes = []
for i in sentence:
	ans.append(arr_1.index(i))
for i in ans:
	if len(arr_1[i]) < len(arr_2[i]):
		notes.append(arr_1[i])
	elif len(arr_1[i]) > len(arr_2[i]):
		notes.append(arr_2[i])
	else:
		notes.append(arr_1[i])
for i in notes:
	print(i, end=' ')


(n, m) = map(int, input().split())
language_one = []
language_two = []
for x in range(m):
	(a, b) = map(str, input().split())
	language_one += [a]
	language_two += [b]
lecture = list(input().split())
for x in lecture:
	b = language_one.index(x)
	if len(x) <= len(language_two[b]):
		print(x, end=' ')
	else:
		print(language_two[b], end=' ')


words = {k: v for (k, v) in (input().split() for i in range(0, int(input().split()[1])))}
print(' '.join((min(w, words[w], key=len) for w in input().split())))


def rii():
	return [int(x) for x in input().split()]
(n, m) = rii()
mapping = {}
for _ in range(m):
	(k, v) = input().split()
	mapping[k] = k if len(k) <= len(v) else v
	mapping[v] = k if len(k) <= len(v) else v
print(' '.join((mapping[w] for w in input().split())))


(n, k) = map(int, input().split())
ll = []
for i in range(k):
	Str = input().split()
	ll.append(Str)
String = input().split()
for i in range(n):
	f = String[i]
	for j in range(len(ll)):
		g = ll[j][0]
		if g == String[i]:
			if len(ll[j][1]) < len(f):
				String[i] = ll[j][1]
				break
print(*String)


temp = str(input()).split(' ')
(x, y) = (int(temp[0]), int(temp[1]))
d = {}
for i in range(y):
	temp = [x for x in input().split(' ')]
	d[temp[0]] = temp[0] if len(temp[0]) <= len(temp[1]) else temp[1]
ans = ''
for i in input().split(' '):
	ans += d[i] + ' '
print(ans[:-1])


(n, m) = map(int, input().split())
abb = {}
for i in range(m):
	(a, b) = input().split()
	c = a if len(a) <= len(b) else b
	abb[a] = c
notes = []
S = input().split()
for s in S:
	notes.append(abb[s])
print(' '.join(map(str, notes)))


(n, m) = input().split(' ')
n = int(n)
m = int(m)
mylib = {}
for i in range(m):
	string = input().split(' ')
	mylib.update({string[0]: string[1]})
letter = input().split(' ')
for i in range(len(letter)):
	if len(letter[i]) <= len(mylib.get(letter[i])):
		print(letter[i], end=' ')
	else:
		print(mylib.get(letter[i]), end=' ')


(n, m) = map(int, input().split())
ws = dict()
for i in range(m):
	(w1, w2) = input().split()
	ws[w1] = w2 if len(w2) < len(w1) else w1
ls = input().split()
rs = [ws[w] for w in ls]
print(' '.join(rs))


(N, M) = map(int, input().split())
map = {}
for i in range(M):
	(w1, w2) = input().split()
	map[w1] = w2
res = []
for w in input().split():
	if len(w) <= len(map[w]):
		res.append(w)
	else:
		res.append(map[w])
print(' '.join(res))


(n, m) = [int(x) for x in input().split()]
lst = {}
for x in range(m):
	x = input().split()
	if len(x[0]) > len(x[1]):
		lst[x[0]] = x[1]
	else:
		lst[x[1]] = x[0]
profs = [x for x in input().split()]

def notes(lst, profs):
	finalWords = []
	for word in profs:
		if word in lst.keys():
			finalWords.append(lst[word])
		else:
			finalWords.append(word)
	return ' '.join(finalWords)
print(notes(lst, profs))


(n, m) = [int(i) for i in input().split()]
words = {}
for i in range(0, m):
	(a, b) = input().split()
	if len(a) > len(b):
		words[a] = b
	else:
		words[a] = a
string = input()
res = string.split()
for word in res:
	print(words[word], end=' ')


(n, m) = map(int, input().split())
slownik = dict()
for i in range(m):
	(a, b) = input().split()
	slownik[a] = b
	slownik[b] = a
a = input().split()
for i in a:
	if len(slownik[i]) < len(slownik[slownik[i]]):
		print(slownik[i], end=' ')
	else:
		print(slownik[slownik[i]], end=' ')


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
(n, m) = zzz()
arr = []
for i in range(m):
	(x, y) = fast().split(' ')
	if len(x) <= len(y):
		arr.append((x, y))
	else:
		arr.append((y, x))
for i in fast().split(' '):
	for j in arr:
		if i in j:
			print(j[0])
			break


(n, m) = tuple(map(int, input().split()))
dic = dict()
for _ in range(m):
	(a, b) = input().rsplit()
	dic[a] = b
words = input().rsplit()
out = list()
for word in words:
	if len(dic[word]) < len(word):
		out.append(dic[word])
	else:
		out.append(word)
print(' '.join(out))


(m, n) = [int(x) for x in input().split(' ')]
dict = {}
for i in range(0, n):
	words = input().split(' ')
	wlen1 = len(words[0])
	wlen2 = len(words[1])
	if (wlen1 < wlen2) | (wlen1 == wlen2):
		dict[words[0]] = words[0]
	else:
		dict[words[0]] = words[1]
script = input().split(' ')
str = ''
for i in script:
	str = str + dict[i] + ' '
print(str.strip())


(n, m) = map(int, input().split())
d = {}
for _ in range(m):
	(x, y) = input().split()
	d[x] = y
s = list(input().split())
for i in range(n):
	if len(s[i]) > len(d[s[i]]):
		s[i] = d[s[i]]
print(' '.join(s))


(n, m) = [int(_) for _ in input().split()]
trans = {}

def better(a, b):
	if len(a) <= len(b):
		return a
	else:
		return b
for i in range(m):
	(a, b) = input().split()
	trans[a] = better(a, b)
	trans[b] = better(a, b)
l = input().split()
s = ''
for i in l:
	s += trans[i] + ' '
print(s)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))
mo = 1000000007
(n, m) = value()
d = defaultdict(int)
for i in range(m):
	(x, y) = svalue()
	if len(x) <= len(y):
		d[x] = x
	else:
		d[x] = y
a = starr()
for i in a:
	print(d[i], end=' ')


(n, m) = map(int, input().split())
(a, b) = ([], [])
for i in range(m):
	(k, l) = map(str, input().split())
	a.append(k)
	b.append(l)
c = list(map(str, input().split()))
k = []
for i in range(n):
	for j in range(m):
		if c[i] == a[j]:
			if len(a[j]) <= len(b[j]):
				k.append(a[j])
			else:
				k.append(b[j])
print(*k)


n = list(map(int, input().split()))
l = []
for i in range(n[-1]):
	j = input().split()
	l += j
c = input().split()
s = ''
for i in c:
	h = l.index(i)
	if h % 2 == 0:
		o = l[h + 1]
		if len(o) == len(i):
			s += i + ' '
		elif len(o) < len(i):
			s += o + ' '
		elif len(i) < len(o):
			s += i + ' '
	else:
		o = l[h - 1]
		if len(o) == len(i):
			s += o + ' '
		elif len(o) < len(i):
			s += o + ' '
		elif len(i) < len(o):
			s += i + ' '
print(s)


(n, m) = map(int, input().split(' '))
arr = []
for i in range(m):
	w = input().split(' ')
	arr.append(w)
k = input().split(' ')
out = []
for i in range(len(k)):
	for j in range(len(arr)):
		if k[i] == arr[j][0] or k[i] == arr[j][1]:
			if len(arr[j][0]) <= len(arr[j][1]):
				out.append(arr[j][0])
			elif len(arr[j][0]) > len(arr[j][1]):
				out.append(arr[j][1])
p = ''
for i in range(len(out)):
	p = p + str(out[i]) + ' '
print(p)