A computer scientist has developed an encryption algorithm. This algorithm takes two inputs – one plain word and another, a key.
Characteristics of inputs are as below.
Plain word: It is a string consisting of lowercase alphabets only.
Key: It is a set of pairs of strings consisting of lowercase alphabets only. For each pair, first string is the plain word and second
string is its secret word. The characters of these secret words are jumbled but lengths of Plain Word and Secret Word are equal.
This algorithm finds the secret characters for each character in the inputted plain word by using the key. Then it combines all the
secret characters in the same order to form a string called the secret word. Finally output this secret word. Below table shows
how secret characters can be obtained from the key.
Your task is to help him in implementing the algorithm as a computer program.
Note: It is guaranteed that all characters in the given plain word can be converted to secret characters by using the given key.
Note: It is guaranteed that one plain text can be converted to only one encrypted text.
1 <= P <= 52000
1 <= N <= 26
1 <= Length of a plain word in pair <= 50000
1 <= Length of a secret word in pair <= 50000
Length (plain word) == Length (secret word)
First line contains string P denoting the plain text.
Second line contains an integer N denoting number of key pairs. Next N lines, each contain two space separated strings denoting plain text and key.
Print the encrypted word.
“load” is the plain word to be encrypted. Given Key contains 3 pairs of Plain word and Secret word combination. They are <“app”,
“lol”>, <“old”, “tip”> and <“odd”, “itt”>. From first pair, it’s clear that the secret character of ‘p’ is ‘l’ and that of ‘a’ is ‘o’. From third pair,
it’s clear that the secret character of ‘d’ is ‘t’ and that of ‘o’ is ‘i’. By using above findings, from second pair, it is clear that the secret
character of ‘l’ is ‘p’. Now we can build the secret word by replacing the characters of plain word by its corresponding secret
characters as “piot”.
The word “a” is the plain word to be converted to secret word. The given key consists of only one plain word – secret word pair.
i.e., <“a”, “b”>. From this, it is clear that the secret character of ‘a’ is ‘b’, since there is only one character in both secret and plain
words. So, the final output is “b”.