#include <string>
#include <iostream>
#include <map>
#include <cstdio>
 
using namespace std;
 
int AffineCipher(int a, int b, const char c){
	return (a*(c-'a')+b)%26 + 'a';
}

int main(){
    string s, s2;
	string kw[] = {"this", "that"};
	string alpha = "abcdefghijklmnopqrstuvwxyz";
	char decode[256];

	int n;
	getline(cin, s);
	n = atoi(s.c_str());
	const int sc = 1000;

    while(n--){
		getline(cin, s);
		string ckw[2] = {kw[0], kw[1]};
		bool found = false;
		int p;

		for(int a = 1; a < sc && !found; a+=2){
			for(int b = 0; b < 26; b++){
				for(int i = 0; i < kw[0].size();i++){
					ckw[0][i] = AffineCipher(a, b, kw[0][i]);
					ckw[1][i] = AffineCipher(a, b, kw[1][i]);
				}
				if(s.find(ckw[0]) != -1 || s.find(ckw[1]) != -1){
//					cout << a << " " << b << endl;
					for(int i = 0; i < 26; i++){
						decode[AffineCipher(a, b, alpha[i])] = alpha[i];
					}
					for(int i = 0; i < s.size(); i++){
						if(isalpha(s[i])){
							s[i] = decode[s[i]];
						}
					}
					cout << s << endl;
					found = true;
					break;
				}
			}
		}
	}
  
    return 0;
}