Codeforces Round 284 (Div. 2)
B
Lecture
Codeforces
1000
原题
← AC →
翻译中…

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.

翻译中…

样例

Input #1
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
Output #1
codeforces round letter round
InputCopy OutputCopy
Input #2
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
Output #2
hbnyiyc joll joll un joll
InputCopy OutputCopy
题目信息
题号
499B
时间限制
1 s
内存限制
256 MB
标签
模拟
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。