Public submissions
Source code of every submission to this problem in this contest will be visible for everyone since 2014-01-28 09:35:50.

SMPCPH1 - Substitution cipher

You are given a sequence of n characters S = s1, s2, ..., sn in such a way that for ij we have also sisj. Your task is to substitute every si with si+1 for i in {1, 2, ... n-1} and sn with s1 in the given plain text.

Input

In the first line you are given one integer 2<=n<=26, and in the following line n characters.

In the third line you are given one integer 2<=m<=100, and in the following m lines you are given a plaintext to be encoded. Plaintext contains only white spaces and small letters from the Latin alphabet. The whole plain text is at most 1000 characters long.

Output

Encoded text, as specified above.

Example 1

Input:
6
spojit
3
after this training 
we will solve even
difficult and tricky problems easily

Output:
afser shtp sratntng
we wtll pjlve even
dtfftculs and srtcky orjblemp eaptly

Example 2

Input:
10
dontgiveup
3
after this training
we will solve even
difficult and tricky problems easily

Output:
afgur ghvs gravtvti
wu wvll snleu ueut
ovffvcplg ato grvcky drnblums uasvly


Added by:kuszi
Date:2014-01-23
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Public source code since: 2014-01-28 09:35:50

hide comments
2015-06-22 06:26:31
easy.. accepted in one go :D

Last edit: 2015-06-22 06:28:03
2014-07-03 04:40:15 iitk_ex039
can anyone please tell whats wrong with this code?
http://ideone.com/1iBYz8

Please!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.