import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

affine a b c
  | isAsciiLower c = chr $ mod (a * (ord c - ord 'a') + b) 26 + ord 'a'
  | otherwise = c

unaffine a b c
  | isAsciiLower c = head [x | x <- ['a'..'z'], affine a b x == c]
  | otherwise = c

  
findAffine s = fromMaybe "" $ find (or . flip map [isInfixOf "that", isInfixOf "that"] . flip ($))  [flip map s $ unaffine a b | a <- [0..25], b <- [0..25], mod a 2 /= 0, mod a 13 /= 0]

main = do
    getInt >>= flip replicateM getLine >>= mapM_ (putStrLn . findAffine)