#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string sent, cp;
	int num;
	cin >> num;
	cin.ignore();
	for(int i = 0; i < num; i++)
	{
		getline(cin, sent);

		for(int j = 0; j < 27; j++)
		{
			for(int k = 0; k < 27; k++)
			{
				cp = sent;

				for(int l = 0; l < sent.size(); l++)
				{
					if(islower(cp[l]))
					{
						cp[l] = (j*(cp[l] - 97)+k) % 26;
						cp[l] += 97;
					}
				}

				if(cp.find("that") != string::npos)
				{
					goto ending;
				}
				else if(cp.find("this") != string::npos)
				{
					goto ending;
				}
			}
		}
ending:;
	   cout << cp << endl;
	}
}