def gcd(m, n)
	if m < n 
		gcd(n, m)
	elsif n == 0
		m
	else
		gcd(n, m % n)
	end 
end

$cache = {}
def inv(a)
	return $cache[a] if $cache[a]
	(1..25).each do |x|
		return $cache[a] = x if a * x % 26 == 1
	end
end

n = gets.to_i
n.times do
	code = gets.chomp
	(1..25).each do |a|
		next if gcd(a, 26) > 1
		(0..25).each do |b|
			decoded = code.each_char.map {|c|
				next c if c == " "
				x = c.ord - ?a.ord
				((x + 26 - b) * inv(a) % 26 + ?a.ord).chr
			}.join
			if decoded =~ /\bthis\b|\bthat\b/
				puts decoded
			end
		end	
	end
end