#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef map <char,char> mapcc;
#define REP(i,n) for (int i=0; i<n; i++)
string A2Z="abcdefghijklmnopqrstuvwxyz";

string decode(mapcc &mp, string &msg){
	string s="";
	int i=0;
	while (msg[i]){
		char c = msg[i];
		if (islower(c)) c = mp[c];
		s += c;
		i++;
	}
	return s;
}

string affine(string &msg, int a=0, int b=0){
	
	mapcc mp;
	REP(i,26){
		int i1 = i*a+b;
		while (i1<0) i1 += 26;
		mp[A2Z[i]] = A2Z[i1 % 26];
	}
	return decode(mp, msg);
}

string rot(string &msg, int a){
	if (a==0) return msg;
	mapcc mp;
	while (a<0) a += 26;
	REP(i,26)
		mp[A2Z[i]] = A2Z[(i+a) % 26];
	return decode(mp, msg);
}

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

int main(void){
	int n;
	cin>>n;
	cin.ignore();
	REP(i,n){
		vi key;
		string msg, word;
		getline(cin, msg);
		istringstream is(msg);
		while(is>>word)
			if (word.size()==4){
				key = find(word);
				if (key[0] != -1) break;
			}
		cout<<affine(msg, key[0], key[1])<<endl;
	}
}