def affine(a, b, r)
  (a * r + b) % 26
end

def a2i(a)
  a.ord - 97
end

def i2a(i)
  (i + 97).chr
end

def solve_sub(r1, p1, r2, p2)
  l = r1 - r2
  r = p1 - p2

  if l < 0
    l *= -1
    r *= -1
  end

  while r < 26
    r += 26
  end

  if r % l == 0
    r /= l
    l /= l
    r %= 26
  else
    return []
  end

  a = r
  b = (p1 - (r1 * a )) % 26

  return [a, b]
end

def solve(s)
  tests = s.split(/ /).select{|w| w.size == 4}

  tests.each do |word|
    %w/this that/.each do |dst|
      res = []

      (0..3).each_slice(2) do |i1, i2|
        res.push(solve_sub(a2i(word[i1]), a2i(dst[i1]), a2i(word[i2]), a2i(dst[i2])))
      end

      if res[0] == res[1]
        return res[0]
      end
    end
  end

  return []
end

while str = STDIN.gets

  break if str == "\n"

  n = str.chomp.to_i

  n.times{
    s = STDIN.gets.chomp
    (a, b) = solve(s)
    puts s.split(//).map{|c| (c != " ") ? i2a(affine(a, b, a2i(c))) : " "}.join
  }

end