#C2000. Replace Words with Synonyms

    ID: 45269 Type: Default 1000ms 256MiB

Replace Words with Synonyms

Replace Words with Synonyms

You are given a list of words and a dictionary that maps some words to their synonyms. Your task is to replace each word in the list with its corresponding synonym if one exists in the dictionary. Otherwise, the word should remain unchanged.

Note: The input will first provide the number of words, followed by the list of words separated by spaces. Then, you will be given the number of synonym pairs, followed by each pair on a new line.

Example:

Input:
4
happy sad angry joyful
3
happy cheerful
sad unhappy
angry mad

Output: cheerful unhappy mad joyful

</p>

Implement the solution so that it reads from standard input and outputs the result to standard output.

inputFormat

The input is given in the following format:

  1. The first line contains an integer N — the number of words.
  2. The second line contains N words separated by spaces.
  3. The third line contains an integer M — the number of synonym pairs.
  4. The following M lines each contain a pair of strings: a word and its synonym, separated by a space.

If N is 0, then the list of words is empty.

outputFormat

Output the transformed list of words in one line, separated by a single space. Each word should be replaced by its synonym if it exists; otherwise, it remains unchanged.

## sample
4
happy sad angry joyful
3
happy cheerful
sad unhappy
angry mad
cheerful unhappy mad joyful