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

char T[27] = "abcdefghijklmnopqrstuvwxyz";

string S, V;
int n;
int x[26];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		S = "";
		while (S == "") {
			getline(cin, S);
		}
		for (int j = 0; j < 26; j++)
		{
			for (int k = 0; k < 26; k++)
			{
				for (int l = 0; l < 26; l++)
				{
					x[l] = -1;
				}
				for (int l = 0; l < 26; l++)
				{
					if (x[(j*l + k) % 26] == -1)
					{
						x[(j*l + k) % 26] = l;
					}
					else
					{
						goto E;
					}
				}
				V = "";
				for (int l = 0; l < S.size(); l++)
				{
					for (int m = 0; m < 26; m++)
					{
						if (T[m] == S[l])
						{
							V += T[x[m]];
							goto G;
						}
					}
					V += S[l];
				G:;
				}
				for (int i = 0; i < S.size() - 3; i++)
				{
					if (V.substr(i, 4) == "this" || V.substr(i, 4) == "that")
					{
						cout << V << endl;
						goto H;
					}
				}
			E:;
			}
		}
	H:;
	}
	return 0;
}