#include<iostream>
#include<string>
#include<sstream>
int calc_alpha(const std::string&w, const char*str)
{
	auto distance = [](char from, char to)
	{
		int result = static_cast<int>(to - from);
		return result + (result < 0 ? 26 : 0);
	};
	int dis[3], ratio[3];
	for (int j = 0; j < 3; j++)
	{
		dis[j] = distance(w[j], w[j + 1]);
		int dis2 = distance(str[j], str[j + 1]);
		while (true)
		{
			if (dis[j] % dis2 == 0)
			{
				ratio[j] = dis[j] / dis2;
				break;
			}
			dis[j] += 26;
		}
	}
	return ratio[0] == ratio[1] && ratio[1] == ratio[2] ? ratio[0] : -1;
}
int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();
	for (int i = 0; i < n; i++)
	{
		std::string str;
		std::getline(std::cin, str);
		std::stringstream ss(str);
		int alpha, beta;
		for (std::string w; ss >> w;)
		{
			if (w.length() == 4)
			{
				alpha = w[0] == w[3] ? calc_alpha(w, "that") : calc_alpha(w, "this");
				if (alpha != -1)
				{
					beta = static_cast<int>(w[0] - 'a' - ('t' - 'a') * alpha % 26);
					break;
				}
			}
		}
		for (auto j : str)
		{
			if (j == ' ')
			{
				std::cout << ' ';
			}
			else
			{
				for (char k = 'a';; k++)
				{
					if (((k - 'a') * alpha + beta) % 26 + 'a' == j)
					{
						std::cout << k;
						break;
					}
				}
			}
		}
		std::cout << std::endl;
	}
	return 0;
}
