//0040 Affine Cipher

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


const int N = 26;
void Transrate(string &refStr, int a, int b)
{
	for(int i = 0; i < refStr.size(); i++)
	{
		refStr[i] = (a*(refStr[i]-'a') + b)%N + 'a';
	}
}

int GCD(int a, int b)
{
	int c;
	while((c = a%b) != 0)
	{
		a = b;
		b = c;
	}
	return b;
}

int main(void)
{
	int n;
	string from, to;
	cin >> n;
	getline(cin, to);	//êsÚÌüsð

	while(n--)
	{
		getline(cin, to);
		int i, j;
		int a, b;
		from.resize(to.size());

		string t1, t2;
		for(a = 1; a < N; a++)
		{
			if(GCD(N, a) != 1)
				continue;
			for(b = 0; b < N; b++)
			{
				t1 = "this";
				t2 = "that";
				Transrate(t1, a, b);
				Transrate(t2, a, b);

				if( (to.find(t1) != string::npos) ||
					(to.find(t2) != string::npos) )
				{
					for(i = 0; i < to.size(); i++)
					{
						if(isalpha(to[i]))
						{
							for(j = 0; j < N; j++)
							{
								if(to[i] == (a*j+b)%N + 'a')
								{
									from[i] = j+'a';
									break;
								}
							}
						}
						else
							from[i] = to[i];
					}
					cout << from << endl;
					goto END;
				}
			}
		}
	END:
		;
	}
	return 0;
}