require 'rational'

class Affine
  def initialize
    @table = {}
    results = []
    create_table
    num = $stdin.gets.chomp.to_i
    num.times do 
      string = $stdin.gets.chomp
      results << check(string)
    end

    results.each do |answer|
      puts answer
    end
  end

  def check(string)
    alpha = 1
    loop do
      1.upto(25) do |beta|
        if 26.gcd(alpha) == 1
          str = convert(string, alpha, beta).split(' ')
          if str.include?('this') || str.include?('that')
            return str.join(' ') 
          end
        end
      end
      alpha += 1
    end
  end

  def create_table
    [*('a'..'z')].each_with_index do |ch, val|
      @table[ch] = val
    end
  end

  def decode(ch, alpha, beta)
    index = (alpha*@table[ch] + beta) % 26
    @table.index(index)
  end

  def convert(string, alpha, beta)
    result = ''
    string.each_char do |ch|
      if ch != ' '
        result += decode(ch, alpha, beta)
      else
        result += ch
      end
    end
    return result
  end
end

a = Affine.new