#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;
#define REP(i,n) for (int i=0; i<n; i++)
string A2Z="abcdefghijklmnopqrstuvwxyz";
struct affine_key{
	int a;
	int b;
};

string decode(string &L1, string &L2, string &msg){
	int n=msg.size();
	string s="";
	REP(i,n){
		char c=msg[i];
		if (c>='a' && c<='z'){
			string::size_type index=L1.find(c);
			s += L2[index];
		}else
			s += c;
	}
	return s;
}

string affine(string &msg, affine_key &key){
	string s="", s2;
	REP(i,26){
		int it=(i*key.a+key.b+26)%26;
		s += A2Z[it];
	}
	return decode(A2Z, s, msg);
}

string rot(string &msg, int a){
	if (a==0) return msg;
	while (a<0)
		a+= 26;
	a %= 26;
	string s = A2Z.substr(a)+A2Z.substr(0,a);
	return decode(A2Z, s, msg);
}

affine_key find(string &msg){
	char c0='t';
	affine_key key;
	for (int i=1; i<26; i+=2){
			key.a=i;
			key.b=0;
		string x=affine(msg, key);
		int a = c0-x[0];
		if (a<0) a += 26;
		x = rot(x,a);
		if (x=="this" || x=="that"){
			key.b=a;
			return key;
		}
	}
	key.a=-1;
	key.b=-1;
	return key;
}

vs split(const string &text, char delim=' '){
    int p1 = 0, p2 = 0;
    vs tokens;
 
    for (int i=0; i<(int)text.size(); i++)
        if (text[i] == delim){
            p2 = i;
            tokens.push_back(text.substr(p1, p2 - p1));
            p1 = p2 + 1;
        }
    tokens.push_back(text.substr(p1));
    return tokens;
}

int main(void){
	int n;
	cin>>n;
	REP(i,n){
		string msg;
		getline(cin, msg);
		vs word = split(msg);
		affine_key key;
		REP(i, word.size())
			if (word[i].size()==4){
				key = find(word[i]);
				if (key.a != -1) break;
			}
			cout<<affine(msg, key)<<endl;
	}
}