This page is still under construction.

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

Shuffle

Interview

Time limit2sMemory limit512 MB

Summary
Given a permutation of 27 characters, apply it N times to a short string and print the result.
Level

Medium5 of 10

Topics
Implementation, Math, String, Simulation
Solved
No attempts yet

Problem

You want to keep some secrets, so you design a simple encryption scheme.

You map each uppercase letter and the underscore character to some other uppercase letter or underscore. In other words, you define a permutation — a one-to-one and onto map — of the 27-character set {'A', 'B', ..., 'Z', '_'} onto itself.

To make your message more secure, you apply this encryption repeatedly.

Input

The input consists of 29 lines.

  • The first 27 lines each contain a single character from the set {'A', 'B', ..., 'Z', '_'}. The first line is the character that 'A' maps to, the second line is the character that 'B' maps to, and so on up to the 26th line for 'Z'; the 27th line is the character that the underscore '_' maps to.
  • The 28th line contains an integer NN (1≤N≤20000000001 \le N \le 2000000000), the number of times the encryption is applied.
  • The 29th line contains a string TT of fewer than 80 characters from the set {'A', 'B', ..., 'Z', '_'}.

Output

Print, on a single line, the string obtained by applying the given permutation to TT exactly NN times.

Examples3

  1. Example 1

    Input
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    Z
    _
    A
    3
    I_LOVE_THE_CCC
    
    Expected output
    LCORYHCWKHCFFF
    
  2. Example 2

    Input
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    Z
    _
    1
    THE_QUICK_BROWN_FOX
    
    Expected output
    THE_QUICK_BROWN_FOX
    
  3. Example 3

    Input
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    R
    S
    T
    U
    V
    W
    X
    Y
    Z
    _
    A
    1
    I_LOVE_THE_CCC
    
    Expected output
    JAMPWFAUIFADDD