cl = [*"a".."z"]
table_a = (1..26).select {|i| 26.gcd(i) == 1}
b = nil

$<.readlines.drop(1).each do |str|
  a = table_a.find do |i|
    b = (0..26).find do |j|
      nominees = str.split.select {|w| w.length == 4}
      ["that", "this"].map do |x|
        nominees.include?(x.chars.map {|c| cl[(i * cl.index(c) + j) % 26]}.join)
      end.any?
    end
  end
  table = (0..25).map {|i| (a * i + b) % 26}
  puts str.chomp.chars.map {|c| (c == " ") ? c : cl[table.index(cl.index(c))]}.join
end
