#C67. String Transformation with Two-Letter Synonyms

    ID: 50488 Type: Default 1000ms 256MiB

String Transformation with Two-Letter Synonyms

String Transformation with Two-Letter Synonyms

You are given a string S and a set of synonym pairs. Each synonym pair consists of two words: a target word and its two-letter synonym. The task is to transform the string S by replacing each word that appears as a target in a synonym pair with its corresponding synonym. If a word does not have a corresponding synonym, it remains unchanged.

The replacement is case-sensitive. That is, if the word does not match exactly (including letter case) with any key in the synonym mapping, it should remain unchanged.

Input Format: The input begins with the original string S on the first line. The second line contains an integer n, representing the number of synonym pairs. Each of the next n lines contains two words separated by a space: the first word is the target to search for in the string and the second word is its two-letter synonym.

Output Format: Output the transformed string after all replacements have been made.

Example:

If S = "hello world" and the synonym pairs are [["hello", "hi"], ["world", "wd"], ["goodbye", "bye"]], then the transformed string is:

( hi\ wd )

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains the string S.
  2. The second line contains an integer n, the number of synonym pairs.
  3. The next n lines each contain two space-separated words. The first is the word to be replaced and the second is its two-letter synonym.

outputFormat

Output the transformed string to standard output (stdout) after performing the replacements described above.

## sample
hello world
3
hello hi
world wd
goodbye bye
hi wd