gets.to_i.times do
  c = gets.chomp
  a, b = nil, nil
  c.split.select {|s| s.size == 4 }.each do |s|
    # this
    a = (s[2].ord - s[1].ord) % 26
    b = ((s[1].ord - ?a.ord) - a * 7) % 26
    break if s == 'this'.each_char.map {|c| ((a * (c.ord - ?a.ord) + b) % 26 + ?a.ord).chr }.join
    # that
    next unless s[0] == s[3]
    a = 15 * (s[1].ord - s[2].ord) % 26
    b = s[2].ord - ?a.ord
    break if s == 'that'.each_char.map {|c| ((a * (c.ord - ?a.ord) + b) % 26 + ?a.ord).chr }.join
  end
  puts c.tr (?a..?z).map {|c| ((a * (c.ord - ?a.ord) + b) % 26 + ?a.ord).chr }.join, (?a..?z).to_a.join
end