#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
int euclid(int a, int b)
{
	if (a < b)swap(a, b);
	if (b == 0)return a;
	else return euclid(b, a%b);
}
char hoge(int a)
{
	return 'a' + a;
}
bool check(string a)
{
	if (a.find("that", 0) != string::npos||a.find("this",0)!=string::npos)
	{
		return true;
	}
	return false;
}
int main()
{
	int n;
	cin >> n;
	cin.ignore();
	while (n--)
	{
		string a;
		bool ok = true;
		getline(cin, a);
		cout << a << endl;
		for (int i = 0;ok; i++)
		{
			if (euclid(i, 26) != 1)continue;
			for (int l = 0; l <= 25&&ok; l++)
			{
				for (int k = 0; k <= 25&&ok; k++)
				{
					int j = (i*l + k)%26;
					if (hoge(j) == a[0])
					{
						string ans = "";
						for (int o = 0; o < a.size(); o++)
						{
							if ('a' <= a[o] && a[o] <= 'z')
							{
								for (int u = 0; u <= 25; u++)
								{
									int h = i*u + k;
									h %= 26;
									if (hoge(h) == a[o])
									{
										ans += hoge(u);
										break;
									}
								}
							}
							else
							{
								ans += " ";
							}
						}
						if (check(ans))
						{
							cout << ans << endl;
							ok = false;
						}
					}
				}
			}
		}

	}
}