#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n ; cin >> n;
	string str; getline(cin,str); //ignore
	while(n--)
	{
		getline(cin,str);
		int alpha[26];
		int a=0,b=0; bool flag=false;
		for( ;a<26;a++)
		{
			if(a%2==0 || a%13==0) continue;
			for(b=0;b<26;b++)
			{
				for(int r=0;r<26;r++) alpha[r]=(a*r+b)%26;
				bool table[26]={0}; int k=0;
				for( ;k<26;k++)
					if(table[alpha[k]]) break;
				if(k<26) break;
				string THIS="", THAT="";
				THAT+=('a'+alpha['t'-'a']); THAT+=('a'+alpha['h'-'a']); THAT+=('a'+alpha[0]); THAT+=('a'+alpha['t'-'a']);
				THIS+=('a'+alpha['t'-'a']); THIS+=('a'+alpha['h'-'a']); THIS+=('a'+alpha['i'-'a']); THIS+=('a'+alpha['s'-'a']);
				for(int i=0;i<str.size();i++)
				{
					string ss=str.substr(i,4);
					if(ss==THAT || ss==THIS) {flag=true; break;}
				}
				if(flag) break;
			}
			if(flag) break;
		}
		string ans="";
		for(int i=0;i<str.size();i++)
		{
			char ch; ch=str[i];
			if(!islower(ch)) ans+=ch;
			else
			{
				for(int j=0;j<26;j++)
					if(alpha[j]==ch-'a') {ans+=('a'+j); break;}
			}
		}
		cout << ans << endl;
		//for(int i=0;i<26;i++) cout << alpha[i] << ' ' ; cout << endl;
	}
}