Sherlock and Cipher 2

3.3

7 votes
Problem

Sherlock finds that now Professor Moriarty is using a new encoding scheme for his messages.

After doing frequency analysis on the new messages he found that the method now used is Caesar cipher.

Now, Moriarty is smart enough to think the message in his head and write it directly in encrypted form, but his agents are not. They first write the original message and then write the encrypted message by shifting each letter. Finally they destroy the original message by tearing it.

To exploit this, Sherlock has ordered the Baker Street Irregulars to collect the paper waste of agents.

Now Sherlock always manages to find a scrap of paper containing a sub string of the original message, corresponding to each message passed.

Help Sherlock to decrypt these messages.

Constrains

1<=N<=120

1<=L<=200

Input: The first line contains a positive integer N. Then 2*N lines follow such that one line contains the encrypted message and next line contains the characters on the scrap of paper and so on.

Output: Print N lines each containing the original message.


Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In the first case the Shift amount is 9. In second the shift is 19.

Editor Image

?