n = gets.chomp.to_i
for _ in 0...n
  flag = false
  t = gets.chomp
  res = ""
  for alpha in 0...26
    break if flag
    for beta in 0...26
      break if flag
      s = t.dup
      for i in 0...s.length
        code = s[i].ord
        if "a".ord <= code && code <= "z".ord
          code -= "a".ord
          code = (alpha * code + beta)%26
          code += "a".ord
        end
        s[i] = code.chr
      end
      u = s.split
      for i in 0...u.length
        if u[i]=="that" || u[i]=="this"
          res = s
          flag = true
          break
        end
      end
    end
  end
  puts res
end