eolymp
bolt
Try our new interface for solving problems
Problems

Encryption

Encryption

Alice thinks it is very inconvenient to have to keep one of her keys in a public--private key pair secret. Therefore she invented a public--public key encryption scheme called the Really Secure Algorithm (RSA). The algorithm works as follows: A \textit{word} is a sequence of between one and ten capital letters (\textbf{A--Z}). A \textit{sentence} is a sequence of words, separated by spaces. The \textit{first public key} is a sentence in which each word is used at most once. The \textit{second public key} is a sentence formed by applying a permutation \textbf{σ} to the words in the first public key. The \textit{plaintext} (the unencrypted message) is a sentence that has exactly as many words as the public keys. (Unlike for the public keys, these words are not necessarily unique.) The \textit{ciphertext} (the encrypted message) is the sentence formed by applying the permutation \textbf{σ} to the plaintext. Given the two public keys and the ciphertext, recover the plaintext. \InputFile On the first line one positive number: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item one line with an integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{1000}): the number of words in each sentence. \item one line with a sentence: the first public key. \item one line with a sentence: the second public key. \item one line with a sentence: the ciphertext. \end{itemize} All words consist of at least \textbf{1} and at most \textbf{10} uppercase letters. \OutputFile Per test case print one line with a sentence: the plaintext.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
4
A B C D
D A B C
C B A P
3
SECURITY THROUGH OBSCURITY
OBSCURITY THROUGH SECURITY
TOMORROW ATTACK WE
Output example #1
B A P C
WE ATTACK TOMORROW
Source 2013 Benelux Algorithm Programming Contest (BAPC), Preliminaries, September 28, Problem E