import Data.List
import Data.Char
import Control.Monad

affine :: Int -> Int -> Char -> Char
affine a b c
    | isAlpha c = chr (impl (ord c - ord 'a') + ord 'a')
    | otherwise = c
        where
            impl :: Int -> Int
            impl c' = (a * c' + b) `mod` 26

nyan :: (Int , Int) -> String -> Maybe String
nyan (a , b) s = if isInfixOf "this" s2 || isInfixOf "that" s2 then Just s2 else Nothing
    where
        s2 = map (affine a b) s

solve :: String -> IO ()
solve s = putStrLn $ maybe undefined id $ foldr (\ x y -> case x of Nothing -> y ; z -> z) Nothing $ map (\ ab -> nyan ab s) [(a,b) | a <- [1..25] , b <- [1..26] , gcd a 26 == 1]

main :: IO ()
main = readLn
    >>= (\ n -> replicateM n getLine)
    >>= mapM_ solve