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

char F(char c, int a, int b)
{
	return ((c-'a')*a + b)%26 + 'a';
}

int main()
{
	string str;
	char str1[8]="that",src1[8]="that";
	char str2[8]="this",src2[8]="this";

	int a,b,n; cin >> n; cin.ignore();
	while(n--)
	{
		getline(cin,str);

		for(a=1; true; a++)
		{
			if(a%2==0 || a%13==0) continue;

			for(b=0; b<26; b++)
			{
				for(int i=0; i<4; i++)
				{
					str1[i] = F(src1[i],a,b);
					str2[i] = F(src2[i],a,b);
				}
				if(str.find(str1)!=string::npos
				|| str.find(str2)!=string::npos)
				{
					goto ex;
				}
			}
		}

		ex:;

		char tb[256];
		for(char i='a'; i<='z'; i++)
		{
			tb[F(i,a,b)] = i;
		}
		tb[' ']=' ';

		for(int i=0; i<str.size(); i++)
		{
			cout << tb[str[i]];
		}
		cout << endl;
	}
}