QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#15511. Synonyms

统计

Sometimes when copying text from Wikipedia into essays, the text can get caught in a plagiarism detection program. To avoid this, one must first rewrite the text in their own words so it doesn’t get flagged by the program. There are many ways to do this, one of which is to run the text through a translation program into another language and then back again. If you’re unlucky, the text may come back too similar to the original despite this.

You could avoid this problem by ensuring that a word is never translated back to the same word if there is another possibility. Formally, assume we have a dictionary with $N$ pairs of words $(a, b)$, where $a$ is the word in Swedish and $b$ is the word in another language. A certain word $x$ can then be changed to the word $y$ if there exist two pairs $(x, z)$ and $(y, z)$ in the dictionary for some word $z$.

Given a text, rewrite it by replacing as many words as possible by translating them to the other language and back.

Input

The first line contains the integer $N$ ($1 \le N \le 5000$), the number of word pairs in the dictionary.

The following $N$ lines each contain a word pair, with the word in Swedish first, followed by the word in the other language. The same word never appears in both languages, and no word pair appears twice.

This is followed by an integer $M$ ($1 \le M \le 1000$), the number of words in the text. The next line contains $M$ words, the text you are to translate. All words appear at least once as a Swedish word in the dictionary.

All words are between $1$ and $20$ letters long and consist only of letters from a-z. It is not guaranteed that the words are actual real words.

Output

Print $M$ words on a single line, the text where as many words as possible have been replaced with a synonym, using the process described in the task. If there are many possible synonyms for a word, you can choose any of them, as long as it is not the same word.

Samples

Input

4
skum foam
skum shady
fradga foam
typ type
2
skum typ

Output

fradga typ

Explanation

There are two translations of “skum”, which are “foam” and “shady”. These can, in turn, be translated back into two different words: “skum” and “fradga”. To avoid translating the word back to “skum”, you must choose “fradga”.

However, for the second word, there is only one translation available, so we have to translate it back to the same word.

Input

3
skum foam
skum shady
fradga foam
2
skum fradga

Output

fradga skum

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

Group Points Constraints
$1$ $56$ All words in the other language has at least two Swedish translations.
$2$ $44$ No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.