2010 Canadian Computing Competition, Stage 2

Day 2, Problem 3: Shuffle

You want to keep some secrets, so you invent a simple encryption algorithm.

You will map each uppercase character and underscore to some other uppercase character or underscore. In other words, this is a permutation of the characters, or, to put it another way, you create a 1:1 and onto map from {'A', 'B', ...., 'Z', '-'} to {'A', 'B', ...., 'Z', '-'}.

However, you will repeatedly apply this encryption in an attempt to make your message more secure.

Input

The input will be 29 lines long. The first 27 lines will each contain a single integer from the set {'A', 'B', ...., 'Z', '-'}. The first of these lines represents what the character 'A' maps to, the second of these lines represents what the character 'B' maps to, and so on, until the 27th line represents what the underscore character maps to.

On the 28th line will be an integer N (1 ≤ N ≤ 2×109), which represents the number of times this encryption should be applied.

On the 29th line is T, a string of less than 80 characters from the set {'A', 'B', ...., 'Z', '-'}.

Output

On one line, output the string created after shuffling T a total of N times, using the given shuffle permutation.

Sample 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

Sample Output

LCORYHCWKHCFFF

All Submissions
Best Solutions


Point Value: 10
Time Limit: 2.00s
Memory Limit: 256M
Added: May 19, 2010

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Is it - or _? The test data and the problem data are telling two different stories.

until the 27th line represents what the underscore character maps to.

I believe '-' is supposed to be '_'.

Should probably update the problem to reflect that.

in sample input, 'Q' seems to map to '3'

Wow, that's pretty weird...but it's been fixed.