class String
    def affine_one (alpha, beta)
        raise 'exception' unless self.size == 1
        return self if self == ' '
        [(((self.bytes.to_a[0]-97) * alpha + beta) % 26) + 97].pack("C")
    end
    def affine (alpha, beta)
        self.scan(/./).map{|x| x.affine_one alpha,beta}.join
    end
    def deaffine_one (alpha, beta)
        raise 'exception' unless self.size == 1
        return self if self == ' '
        [[*'a'..'z'].join.affine(alpha,beta).index(self) + 97].pack("C")
            
        #[26.lcm((self.bytes.to_a[0] - 97) - beta)  / alpha + 97].pack("C")
    end
    def deaffine (alpha, beta)
        self.scan(/./).map{|x| x.deaffine_one alpha,beta}.join
    end
end

n = gets.to_i
n.times do
    str = gets.chomp

    alpha = 1; beta = nil; passed = false
    loop do
        (alpha += 2; redo)if alpha == 13

        (0..25).each do |beta|
            passed = true if str.include?('that'.affine(alpha, beta))
            passed = true if str.include?('this'.affine(alpha, beta))
            puts str.deaffine(alpha, beta) if passed
            break if passed
        end
        break if passed
        alpha += 2
    end

end