GCPC11F - Diary

Nowadays, people who want to communicate in a secure way use asymmetric encryption algorithms such as RSA. However, my older brother uses another, simpler encryption method for his diary entries. He uses a substitution cipher where each letter in the plaintext is substituted by another letter from the alphabet. The distance between the plaintext letter and the encrypted letter is fixed. If we would define this fixed distance d to 5, A would be replaced by F, B by G, C by H ... Y by D, Z by E.

With a fixed and known distance d the decryption would be somewhat simple. But my brother uses random distances for each of his diary entries. To decrypt his diary I have to guess the distance d for each entry. Thus, I use the well known phenomenon that the letter E is used more often in English words than other letters. Can you write a program for me that calculates the distance d based on the fact that the most used letter in the encrypted text corresponds to the letter E in plaintext? Of course, I am interested in the decrypted text, too.

Input

The input consists of several test cases c that follow (1 ≤ c ≤ 100). Each test case is given in exactly one line containing one diary entry. Diary entries only use upper case letters (A-Z) and spaces. Each diary entry consists of at most 1000 encrypted letters (including spaces).

Output

For each test case, print one line containing the smallest possible distance d (0 ≤ d ≤ 25) and the decrypted text. If the decryption is not possible because there are multiple distances conforming to the rules above, print NOT POSSIBLE instead. Spaces are not encrypted.

Example

Input:
4
RD TQIJW GWTYMJWX INFWD JSYWNJX ZXJ F XNRUQJ JSHWDUYNTS YJHMSNVZJ
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
XVIDRE TFCCVXZRKV GIFXIRDDZEX TFEKVJK UVTIPGKZFE
XVIDRE TFCCVXZRKV GIFXIRDDZEX TFEKVJK

Output:
5 MY OLDER BROTHERS DIARY ENTRIES USE A SIMPLE ENCRYPTION TECHNIQUE
10 JXU GKYSA RHEMD VEN ZKCFI ELUH JXU BQPO TEW
17 GERMAN COLLEGIATE PROGRAMMING CONTEST DECRYPTION
NOT POSSIBLE

Added by:Adrian Kuegel
Date:2011-07-05
Time limit:0.407s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:German Collegiate Programming Contest 2011 (Author: Tobias Werth)

hide comments
2012-02-13 19:23:49 karthik
@Adrian,pls check my code too...
i too keep getting WA
2012-02-07 14:41:59 Rachmawan Atmaji Perdana
The answer of
BB C
is
23 EE F
Y Not 3 EE F (it's absolute of -3, since using 'shift left')
2012-02-04 15:36:46 Rachit Tandon
@Adrian - I m getting the correct answer for every possible test i could think of .
can u tell me what's wrong with my code, i m getting WA.
6421795
2012-02-02 14:16:46 Adrian Kuegel
There are four 'X' and four 'V' in the last example test case. So how should you determine which of these two letters is mapped to 'E'?
2012-02-01 11:56:25 :P
why the fourth case is not possible?..as we have to take smallest possible distance which is unique
2012-01-21 17:36:20 saket diwakar
enjoyed to solve it...really nice problem
2012-01-06 05:13:04 Abhra
@Adrian
pls check my code once...
all test cases runs fine and i have even tried input for d>21, everything works fine but am getting WA....

submission #6302375
2011-12-11 10:39:34 Rajkiran Rajkumar
Adrian, can you please check out my code? Thanks :)
2011-10-27 17:45:57 nilaysahu
distance between E and A is 22 not 4
2011-10-11 18:36:04 sri
its WA again and again??
its working fine for all test cases.
any tricky case?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.