#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

vector<string> split_naive(const string &s, char delim) {
	vector<string> elems;
	string item;
	for(char ch:s){
		if(ch==delim){
			if(!item.empty()) elems.push_back(item);
			item.clear();
		}
		else{
			item += ch;
		}
	}
	if(!item.empty()) elems.push_back(item);
	return elems;
}

ll extend_gcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x = 1;
		y = 0;
		return a;
	}
	ll d = extend_gcd(b,a%b,y,x);
	y -= a/b * x;
	return d;
}

ll mod(ll a,ll m){
	return (a%m+m)%m;
}

ll modinv(ll a,ll m){
	ll x,y;
	extend_gcd(a,m,x,y);
	return mod(x,m);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	vector<int> A,Ainv;
	REP(i,26){
		if(gcd(i+1,26)==1){
			A.push_back(i+1);
		}
	}
	int N;
	char S[280];
	cin.getline(S,sizeof(S));
	sscanf(S,"%d",&N);
	REP(n,N){
		cin.getline(S,sizeof(S));
		auto T = split_naive(string(S),' ');
		bool exist = false;
		int ansA,ansB;
		for(auto& alpha:A){
			for(int beta=0;beta<26;beta++){
				string THAT = "that";
				string THIS = "this";
				for(int i=0;i<4;i++){
					THAT[i] = (char)((alpha*(THAT[i]-'a')+beta)%26)+'a';
					THIS[i] = (char)((alpha*(THIS[i]-'a')+beta)%26)+'a';
				}
				for(auto& x:T){
					if(x==THAT || x==THIS){
						exist = true;
						break;
					}
				}
				if(exist){
					ansB = beta;
					break;
				}
			}
			if(exist){
				ansA = alpha;
				break;
			}
		}
		for(int i=0,ei=280;i<ei;i++){
			if(S[i]>='a' && S[i]<='z'){
				S[i] = (char)((modinv(ansA,26)*mod((S[i]-'a')-ansB,26))%26)+'a';
			}
		}
		out(S);
	}

	return 0;
}

