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

hide comments
2018-09-19 14:22:23
i did not understand the question,can any on explain it...plz

Last edit: 2018-09-19 14:22:57
2017-05-08 18:07:33
how to input string characterwise??
2016-08-02 09:17:18
I don't know what's going on.. my result in my local compiler is the same as the example. anyone could give me a suggestion?
2016-06-05 08:13:23
Ah... There's a \n after every line and I was checking what's wrong for 5WAs
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.