This page is still under construction.

Parts of this page are still being built. What you see may change.

Ironclad Security Algorithm

Interview

Time limit1sMemory limit256 MB

Summary
You invert the word permutation defined by the two public keys and apply it to the ciphertext to recover the plaintext.
Level

Easy2 of 10

Topics
Hash map, Array
Solved
No attempts yet

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 ii-th word of the second public key is the jj-th word of the first public key, then the ii-th word of the ciphertext is the jj-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, nn (1≤n≤10001 \le n \le 1000)
  • 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.

Examples1

  1. Example 1

    Input
    2
    4
    A B C D
    D A B C
    C B A P
    3
    SECURITY THROUGH OBSCURITY
    OBSCURITY THROUGH SECURITY
    TOMORROW ATTACK WE
    
    Expected output
    B A P C
    WE ATTACK TOMORROW