#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<numeric>
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define MOD 26
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
typedef pair<int,int> Pii;
typedef vector<int> vi;
int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		getchar();
		string str;
		getline(cin,str);
		set < string > target;
		rep(i,str.size()-3){
			string sub(str,i,4);
			if(i == 0){
				if(str[4] == ' ' || str[4] == '\0'){
					if(str[0] != ' '&&str[1] != ' '&&str[2] != ' '&&str[3] != ' '){
						target.insert(sub);
					}
				}
			}
			else if(i == str.size()-4){
				if(str[str.size()-5] == ' '){
					if(str[i] != ' '&&str[i+1] != ' '&&str[i+2] != ' '&&str[i+3] != ' '){
						target.insert(sub);
					}
				}
			}
			else{
				if(str[i-1] == ' ' && str[i+4] == ' '){
					if(str[i] != ' '&&str[i+1] != ' '&&str[i+2] != ' '&&str[i+3] != ' '){
						target.insert(sub);
					}
				}
			}
		}
		string en = "abcdefghijklmnopqrstuvwxyz";
		string ans = "";
		int i = 0;
		int alpha;
		int beta;
		while(++i){
			if(i%2 == 0 || i%13 == 0)continue;
			rep(j,26){
				rep(k,2){
					string sub;
					if(k == 0){
						sub = "this";
					}
					if(k == 1){
						sub = "that";
					}
					rep(l,4){
						sub[l] = en[((i*(sub[l]-'a')+j) % MOD)];
					}
					if(target.count(sub)){
						alpha = i;
						beta = j;
						goto end;
					}
				}
			}
		}
		end:;
		map < char , char > memo;
		rep(i,26){
			memo[en[((alpha*i+beta) % MOD)]] = en[i];
		}
		rep(i,str.size()){
			if(str[i] == ' ')ans += " ";
			else ans += memo[str[i]];
		}
		cout << ans << endl;
	}
	return 0;
}