import Data.Char
import Data.List

main = interact $ unlines . map affine_cipher . tail . lines

affine_cipher str = affine a b str
 where
  (a,b) = try (sequence [cand_a,cand_b]) (filter ((==4) . length) $ words str)
  try ([a,b]:cands) words4
   | any (\w -> intersect (words $ affine a b w) ["that","this"] /= []) words4 = (a,b)
   | otherwise = try cands words4
  cand_a = filter (\x -> gcd x 26 == 1) [1..100]
  cand_b = [0..25]

affine a b str = encode str
 where
  encode [] = []
  encode (c:cs)
   | isLower c = to_lower ((a * to_digit c + b) `mod` 26) : encode cs
   | otherwise = c : encode cs
  to_digit c = length (takeWhile (/= c) "abcdefghijklmnopqrstuvwxyz")
  to_lower n = head (drop n "abcdefghijklmnopqrstuvwxyz")