arr = (1..26).select{|i| 26.gcd(i)==1}
c = ('a'..'z').to_a
gets.to_i.times do
  s = gets
  hints = s.split.select{|i| i.size==4}
  @alpha = arr.find do |a|
    @beta = (0..26).find do |b|
      ["this", "that"].any?{|h|
        hints.include?(h.chars.map{|i| c[(a*c.index(i)+b)%26]}.join)
      }
    end
  end
  map = (0..25).map{|i| (@alpha*i+@beta)%26}
  puts s.chars.map{|i| c.include?(i) ? c[map.index(c.index(i))] : i }.join
end