Ironclad Security Algorithm
InterviewTime limit1sMemory limit256 MB
You invert the word permutation defined by the two public keys and apply it to the ciphertext to recover the plaintext.
Problem
Sohee decided that keeping a public key and a private key in sync was too much trouble, so she built a cipher that uses only public keys and named it the ironclad security algorithm.
A word is a string of 1 to 10 uppercase letters (A-Z), and a sentence is a list of words separated by single spaces.
The first public key is a sentence in which no word appears twice.
The second public key is the first public key with its words moved to new positions.
A plaintext is a sentence with the same number of words as the first public key. Unlike the key, it may use the same word more than once.
The ciphertext is the plaintext with its words moved the very same way. That is, if the -th word of the second public key is the -th word of the first public key, then the -th word of the ciphertext is the -th word of the plaintext.
Given the two public keys and a ciphertext, recover the plaintext.
Input
The first line has the number of test cases, which is at most 100.
Each test case takes four lines.
- first line: the number of words in one sentence, ()
- second line: the first public key
- third line: the second public key
- fourth line: the ciphertext
Every word is 1 to 10 uppercase letters.
Output
For each test case, print the recovered plaintext on one line, with a single space between words.