Hide

Problem A
Cypher Decypher

/problems/cypherdecypher/file/statement/en/img-0001.jpeg
A spy from Bowser’s army.

Princess Peach is trying to organize the armies of Mushroom Kingdom to repel Bowser’s attack. However, her orders keep getting intercepted by Bowser’s top spy Mr. L. Peach has tried multiple encryption methods, but Mr. L has cleverly decrypted all attempts. However, Peach’s espionage unit has just found out that Mr. L doesn’t know how to multiply numbers! They quickly designed a cypher to exploit this.

The MKIA (Mushroom Kingdom Intelligence Agency) has designed the following mapping from numbers to characters: $0-25$ corresponds to $A-Z$, and this pattern repeats forever: $26-51:A-Z, 52-77:A-Z, \ldots $. The MKIA first selects some secret sequence of numbers $s_1s_2\ldots s_ l$ Given the secret number string, the MKIA can encrypt a message as follows:

  1. For each character in the message, use the MKIA mapping to find its corresponding number.

  2. Multiply that number with the corresponding digit in the secret number string.

  3. Use the MKIA mapping to transform this result back into a character for the encrypted result.

Given a number string and a series of messages, return the encrypted messages after applying the previous algorithm.

Input

The first line is a sequence of digits representing the multiplier in each position of the test cases. This has length $l$ where $1 \leq l \leq 100$. The second line represents $n$, the number of test cases. $1 \leq n \leq 1\, 000$ The next $n$ lines are the messages to be encoded. These messages are guaranteed to have length $l$.

Output

Output $n$ lines containing the encoded strings.

Sample Input 1 Sample Output 1
17247
2
HELLO
WORLD
HCWSU
WUISV
Sample Input 2 Sample Output 2
010281
3
THANKS
TOJANE
STREET
AHAACS
AOAAAE
ATAIGT
Sample Input 3 Sample Output 3
0102
8
ONEF
ISHT
WOFI
SHRE
DFIS
HBLU
EFIS
HHHH
ANAK
ASAM
AOAQ
AHAI
AFAK
ABAO
AFAK
AHAO

Please log in to submit a solution to this problem

Log in