#include <iostream>
#include <string>
#include <cctype>
using namespace std;

string tar[] = { "this", "that" };

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

int main()
{
	string in;
	int N;
	cin >> N;
	getline(cin, in);
	while (N--)
	{
		getline(cin, in);
		string ans;
		bool f = false;
		for (int a=1;; a++)
		{
			if (gcd(a, 26) != 1) continue;
			for (int b=0; b<26; b++)
			{
				ans = in;
				for (int i=0; i<in.size(); i++)
					if (islower(ans[i]))
						ans[i] = (char) ((int) 'a' + (a * ((int) ans[i]) + b) % 26);
	

				if (ans.find(tar[0], 0) != string::npos || ans.find(tar[1], 0) != string::npos)
				{
					f = true;
					break;
				}
			}
			if (f)
				break;
		}

		cout << ans << endl;

	}
}