def foo(m,n)
	while m != n
		m>n ? m -= n : n -= m
	end
	m
end

def max(m,n)
	m > n ? [m,n] : [n,m]
end

na = Hash.new
an = Hash.new
('a'..'z').each_with_index {|c,i| an[c] = i;na[i] = c}
n = gets.chomp.to_i
max = 1000
n.times do
	line = gets.chomp
	decoded = " "*line.size
	1.upto(max) do |a|
		next if foo(*max(a,26)) != 1
		flag = false
		0.upto(max)	do |b|
			temp = (0..25).map{|y| (a*y+b).modulo(26)}
			next if temp.size > temp.uniq.size
			0.upto(line.size-1) {|i| decoded[i] = (line[i] == ' ' ? ' ' : na[(an[line[i]]*a+b).modulo(26)])} 
			flag = true if decoded.include?("this") || decoded.include?("that")
			break if flag
		end
		break if flag
	end
	puts decoded
end