ENCRYPT IT

5

2 votes
Hard
Problem

The problem is simple you just have to encrypt a message using 2 keys.

You are given a message of length n, an integer key and a string key. First, add the integer key to every individual characters of the message. After that, the resulting encrypted message is represented using an integer matrix of order n*1. Representation will follow this pattern: A=0, B=1, C=2 and so on. Consider there are only capital letters in the message. Add the first key (Integer key) into the second key which is a  (String(Upper Case)) of size n*n, and represent the resulting string into a matrix of order n*n in the same way the first decrypted message was represented. After that multiply this matrix with the first matrix and find the equivalent alphabet for each number in the product matrix. For better understanding, see the sample explanation section.


INPUT FORMAT

  • The first line of the input contains a single integer T denoting the number of test cases.
  • The first line of each test case contains a single integer N.
  • The second line contains a string of length n.
  • The third line contains the first key.
  • The fourth line contains the second key on length n*n.

OUTPUT FORMAT

For each test case, print a single line containing the encrypted message


.CONSTRAINTS

  • 1 ≤ t ≤109
  • 1 ≤ n ≤109
Sample Input
1
3
AAA
3
ABCDEFGHI
Sample Output
KLM
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Here the message is AAA

Integer key is 3

String key is ABCDEFGHI

When 3 is added to string AAA we get DDD. Equivalent matrix for 'DDD' will be:

3
3
3

The other key is ABCDEFGHI after adding the first key in it, the resulting string will be 'DEFGHIJKL', its equivalent matrix will be:

4 5
6 7 8
9 10 11

 

Multiplying these 2 matrices we will get 

10
11
12

Whose equivalent alphabets are 'KLM', which is the encrypted message and thus the output.

Editor Image

?