#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>

using namespace std;
// F(y) = (a*y+b) mod 26
int main(){
	int n;
	scanf("%d",&n);
	bool f = false;
	while( n-- ){
		char hoge;
		hoge = getchar();
		string str;
		vector < string > vs;
		getline(cin,str);
		if(f){
			string tmp;
			tmp = hoge;
			tmp += str;
			swap(tmp,str); 
		}
		f = true;
		str+=" ";
		for(int i = 0; i < str.size()-5; i++){
			if(str[i] != ' ' && str[i+1] != ' ' && str[i+2] != ' ' && str[i+3] != ' ' && str[i+4] == ' '){
				string tmp = "";
				tmp += str[i];tmp+=str[i+1];tmp+=str[i+2];tmp+=str[i+3];
				vs.push_back(tmp);
			}
		}
		
		/*for(int i = 0; i < vs.size(); i++){
			cout << vs[i] << endl;
		}*/
		
		int a;
		int b;
		int index = 10000;
		int A = 1000;
		int B = 1000;
		int This[4];
		int That[4];
		for(int i = 1; i < A; i++ ){
			if(__gcd(i,26) != 1)continue;
			for(int j = 1; j < B; j++){
				if(__gcd(i,j) != 1)continue;
				This[0] = (i*('t'-'a')+j);
				This[1] = (i*('h'-'a')+j);
				This[2] = (i*('i'-'a')+j);
				This[3] = (i*('s'-'a')+j);
				
				That[0] = (i*('t'-'a')+j);
				That[1] = (i*('h'-'a')+j);
				That[2] = (i*('a'-'a')+j);
				That[3] = (i*('t'-'a')+j);
				
				for(int k = 0; k < vs.size(); k++){
					string x = "";
					string y = "";
					for(int q = 0; q < 4; q++)x+=(This[q]%26+'a');
					for(int q = 0; q < 4; q++)y+=(That[q]%26+'a');
					if(x == vs[k]){
						index = k;
						a = i;
						b = j;
						goto L;
					}
					if(y == vs[k]){
						a = i;
						b = j;
						index = k;
						goto L;
					}
				}
			}
		}
		L:;
		//printf("a = %d b = %d index = %d\n",a,b,index);
		string ans = "";
		for(int i = 0; i < str.size()-1; i++){
			int x = 0;
			if(str[i] == ' '){ans += " ";continue;}
			while((str[i]-'a'-b+x)%(a)!= 0)x+=26;
			ans += (str[i]-'a'-b+x)/a%26+'a';
		}
		cout << ans << endl;
	}
	return 0;
}