suspection = [1,3,5,7,9,11,15,17,19,21,23,25]
word = ["that", "this"]
def code(word, a, b = 0)
  return word.split(//).map{|char|
    (((char.ord - "a".ord) * a + b) % 26 + "a".ord).chr}.join
end
26.times do |i|
  word << code(word[0], 1, i) << code(word[1], 1, i)
end
gets.to_i.times do
  state = gets
  i = 0
  while (word & (state.split(/\W+/).map{|tango| code(tango, suspection[i])})).size == 0
    i += 1
  end
  b = 0
  while (word[0..1] & (state.split(/\W+/).map{|tango| code(tango, suspection[i], b)})).size == 0
    b += 1
  end
  puts state.split(/\W+/).map{|tango| code(tango, suspection[i], b)}.join(" ")
end