PROG0145 - Atbash

Atbash is a way of coding and decoding messages, originally intended for the Hebrew alphabet. It consists of substituting aleph (the first letter) for tav (the last letter), beth (the second letter) for shin (the one before last letter), and so on, reversing the alphabet. Hence the name, Aleph-Tav-Beth-Shin (אתבש). In the Book of Jeremiah, לב קמי Lev Kamai (51:1) is Atbash for כשדים Kasdim (Chaldeans), and ששך Sheshakh (25:26; 51:41) is Atbash for בבל Bavel (Babylon). It has been associated with the esoteric methodologies of Jewish mysticism's interpretations of Hebrew religious texts as in the Kabbalah. Atbash also occurs in the best seller The Da Vinci Code written by Dan Brown.

The Atbash cipher for the Latin alphabet can be written as follows:

A B C D E F G H I J K L M

Z Y X W V U T S R Q P O N

Coding and decoding both work the same way. One looks up the letter that needs to be coded or decoded in the above representation, and replaces it by the letter above or below. In doing so, uppercase letters must be replaced by their encoded uppercase letters, and lowercase letters by their encoded lowercase letters according to the rules of the Atbash cipher. All other characters (spaces, digits, punctuation marks, …) should remain unchanged in the coded message. Note that applying the Atbash coding scheme on a message that was already encoded according to the Atbash cipher, will return the original message.

Input

The first line of the input contains a number $t \in \mathbb{N}$ that indicates the number of test cases. This is followed by another $t$ lines of input, each containing a sentence that needs to be encoded or decoded according to the rules of the Atbash cipher.

Output

The encoded or decoded message that corresponds to each of the sentences from the input.

Example

Input:

5
The five boxing wizards jump quickly.
Gsv urev ylcrmt draziwh qfnk jfrxpob.
I'm having spam, spam, chips and spam.
Always look on the bright side of life.
We are no longer the knights who say ni!

Output:

Gsv urev ylcrmt draziwh qfnk jfrxpob.
The five boxing wizards jump quickly.
R'n szermt hkzn, hkzn, xsrkh zmw hkzn.
Zodzbh ollp lm gsv yirtsg hrwv lu oruv.
Dv ziv ml olmtvi gsv pmrtsgh dsl hzb mr!

Atbash is een manier om berichten te coderen en te decoderen. Hierbij wordt gebruik gemaakt van een eenvoudige substitutie. De naam van het geheimschrift is afkomstig uit het Hebreeuws en slaat op de werking van de codering: vervang aleph (de eerste letter) door tav (de laatste letter), beth (de tweede letter) door shin (de voorlaatste letter), enzoverder, waardoor het alfabet als het ware wordt omgekeerd. Atbash komt voor in de het Bijbelboek Jeremia (25:26, 54:41) en wordt geassocieerd met de esoterische methodologieën van Joodse mystici. De Atbashcodering komt ook voor in de door Dan Brown geschreven bestseller De Da Vinci Code.

De Atbash versleuteling voor het Romeinse alfabet kan als volgt worden voorgesteld:

A B C D E F G H I J K L M

Z Y X W V U T S R Q P O N

Om te coderen of decoderen zoekt men de te versleutelen letter en vervangt deze door de corresponderende letter daarboven of daaronder. Hierbij moeten hoofdletters vervangen worden door hun gecodeerde hoofdletter en kleine letters door hun gecodeerde kleine letter volgens de regels van de Atbashcodering. Alle overige lettertekens (spaties, cijfers, leestekens, …) blijven ongewijzigd in de gecodeerde tekenreeks. Merk op dat als je de Atbashcodering toepast op een gecodeerde tekst, je automatisch opnieuw de oorspronkelijke tekst bekomt.

Invoer

De eerste regel van de invoer bevat een natuurlijk getal $t$ dat aangeeft hoeveel testgevallen er zijn. De volgende $t$ regels van de invoer bevatten elk een zin die moet gecodeerd of gedecodeerd worden volgens het Atbash geheimschrift.

Uitvoer

De gecodeerde of gedecodeerde tekst voor elk van de zinnen uit de invoer.

Voorbeeld

Invoer:

5
De kunst van het oorlogsvoeren.
Wv pfmhg ezm svg llioltelvivm.
You don't frighten us, English pig dogs.
Go and boil your bottoms, you sons of a silly person.
I blow my nose at you, so-called "Arthur King", you and all your silly English Knights.

Uitvoer:

Wv pfmhg ezm svg lliolthelvivm.
De kunst van het oorlogvoeren.
Blf wlm'g uirtsgvm fh, Vmtorhs krt wlth.
Tl zmw ylro blfi ylgglnh, blf hlmh lu z hroob kvihlm.
R yold nb mlhv zg blf, hl-xzoovw "Zigsfi Prmt", blf zmw zoo blfi hroob Vmtorhs Pmrtsgh.

Added by:Peter Dawyndt
Date:2011-08-08
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.