With Christmas rapidly approaching, you have planned gifts for your friends and secured a Christmas tree. However, you cannot forget about your own gift! You have created a wishlist consisting of items, but the only problem is that it is encoded. You hid the cipher in the CS Club classroom and have now retrieved it. The cipher is a by grid consisting of lowercase letters formatted like the one given below.
1 | 2 | 3 | 4 | 5 | |
---|---|---|---|---|---|
A | q | w | a | r | t |
B | y | u | i | o | p |
C | e | s | d | f | g |
D | h | j | k | l | x |
E | c | v | b | n | m |
The coded version of a character consists of its coordinates like so: [letter, number]. For example, the coded version of the letter b
would be E3
. By this logic, words can be coded and decoded. For example, the word bike
would be E3B3D3C1
when encoded. Note that any cipher will always contain 25 letters, meaning that one letter will always be missing. This excluded letter will not be encoded in the list. For example, E3zB3D3C1
would translate to bzike
.
Your job is to create a program that, given the cipher in the form of a by grid and the coded wishlist, will output the decoded version of all items on the list.
Constraints
Note: It is guaranteed that all strings will be decodable using the given cipher and set of rules in the problem statement.
Subtask 1 [40%]
The items in the list will not contain the excluded letter from the cipher.
Subtask 2 [60%]
No additional constraints.
Input Specification
The first line will contain a single integer, , representing the number of items on your wishlist.
The next five lines will contain the cipher: each line will contain five space-separated characters representing a row of the grid.
The next lines of input will each contain a string , representing an encoded version of an item on your wishlist.
Output Specification
The output should consist of lines: the th line of output should contain a string representing the decoded version of the th item on the wishlist.
Sample Input
Note: You will not be required to pass this sample case to progress to the subtasks.
4
q w a r t
y u i o p
e s d f g
h j k l x
c v b n m
E3B3D3C1
E2B3C3C1B4C5A3E5C1
C2A2C1A3A5C1A4
E3zB3D3C1
Sample Output
bike
videogame
sweater
bzike
Explanation of Sample
The cipher given in this case corresponds to the example given in the problem statement. Using the coding system explained shows that each decoded version corresponds to the coded ones in the input.
Comments