#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

string S,coded;

int gcd(int a,int b){
	if (b==0) return a;
	return gcd(b,a%b);
}
							
int main(){
	int n;
	cin>>n;
	cin.ignore();
	REP(t,n){
		getline(cin,S);
		REP(a,26){
			if (gcd(a,26)!=1) continue;
			REP(b,26){
				coded.clear();
				REP(i,S.length()	){
					if (S[i]==' '){
						coded.push_back(' ');
					}else{
						int y=S[i]-'a';
						int c=a*y+b;
						c%=26;
						coded.push_back((char)(c+'a'));
					}
				}
				cout<<endl;
				if (coded.find("that")!=string::npos || coded.find("this")!=string::npos){
					cout<<coded<<endl;
					a=b=26;
				}
			}
		}
	}
	return 0;
}