#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cstdint>

uint32_t
search_this_and_that(uint32_t const a, std::vector<std::string> const& len4words)
{
	using namespace std;

	char const ciphered_t = ('t' - 'a') * a % 26;
	char const ciphered_h = ('h' - 'a') * a % 26;
	char const ciphered_a = ('a' - 'a') * a % 26;
	char const ciphered_i = ('i' - 'a') * a % 26;
	char const ciphered_s = ('s' - 'a') * a % 26;

	for (string const& word : len4words) {
		if ((word[0] + 26 - word[1]) % 26 == (ciphered_t + 26 - ciphered_h) % 26) {
			if (word[0] == word[3] &&
					(word[1] + 26 - word[2]) % 26 == (ciphered_h + 26 - ciphered_a) % 26) {
				return (word[0] - 'a' + 26 - ciphered_t) % 26;
			}
			else if ((word[1] + 26 - word[2]) % 26 == (ciphered_h + 26 - ciphered_i) % 26 &&
					(word[2] + 26 - word[3]) % 26 == (ciphered_i + 26 - ciphered_s) % 26) {
				return (word[0] - 'a' + 26 - ciphered_t) % 26;
			}
		}
	}
	return 26;
}

int main()
{
	using namespace std;

	string input;
	getline(cin, input);
	uint32_t const n = stoul(input);

	for (uint32_t i = 0; i < n; ++i) {
		getline(cin, input);

		vector<string> len4words;
		string::size_type pos = 0;
		string::size_type next_pos = 0;
		while ((next_pos = input.find(' ', pos)) != string::npos) {
			if (next_pos - pos == 4) {
				len4words.push_back(input.substr(pos, 4));
			}
			pos = next_pos + 1;
		}
		if (input.size() - pos == 4) {
			len4words.push_back(input.substr(pos, 4));
		}

		for (uint32_t a = 1; a < 26; a += 2) {
			if (a == 13) {
				continue;
			}

			uint32_t const b = search_this_and_that(a, len4words);
			if (b != 26) {
				std::array<char, 26> ciphered_to_org;
				for (char c = 'a'; c < 'z' + 1; ++c) {
					ciphered_to_org[(a * (c - 'a') + b) % 26] = c;
				}
				for (char c : input) {
					if (c == ' ') {
						cout << c;
					}
					else {
						cout << ciphered_to_org[c - 'a'];
					}
				}
				cout << endl;
				break;
			}
		}
	}
}