#include <iostream>
#include <cstdio>
#include <map>

#define F(n, a, b) (((a) * (n) + (b)) % 26 + 'a')
#define N(n) ((n) - 'a')

using namespace std;

int gcd(int a, int b) {
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main() {
	string str, ans = "";
	string _this = "this", _that = "that";
	string __this = "", __that = "";
	int n, a, b;
	getline(cin, str);
	sscanf(str.c_str(), "%d", &n);
	for (int i = 0; i < n; i++) {
		getline(cin, str);
		for (a = 1; a < 26; a++) {
			if (gcd(a, 26) != 1)
				continue;
			for (b = 0; b < 26; b++) {
				__this = __that = "";
				for (int j = 0; j < 4; j++) {
					__this += (char)F(N(_this[j]), a, b);
					__that += (char)F(N(_that[j]), a, b);
				}
				if (str.find(__this) != string::npos || str.find(__that) != string::npos)
					goto END;
			}
		}
END:
		string alpha = "abcdefghijklmnopqrstuvwxyz";
		map<char, char> decrypt;
		for (int j = 0; j < 26; j++)
			decrypt[(char)F(N(alpha[j]), a, b)] = alpha[j];
		ans = "";
		for (int j = 0; j < str.size(); j++) {
			if (isalpha(str[j]))
				ans += (char)decrypt[str[j]];
			else
				ans += (char)str[j];
		}
		cout << ans << endl;
	}
	return 0;
}