#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string str,w1,w2;
  int n,a,b,c;
  int da[26];
  cin >> n;
   while(n>0) {
	  getline(cin,str);
	  if (str.size()==0) continue;
	    for (a=1;a<26;a+=2) {
		  if (a==13) continue;
		  for (b=0;b<26;b++) {
			  w1="this"; w2="that";
			  for (c=0;c<4;c++) {
				  w1[c]=char('a'+((a*(w1[c]-'a')+b) % 26));
                  w2[c]=char('a'+((a*(w2[c]-'a')+b) % 26));
			  }
              if (str.find(w1)!=string::npos || str.find(w2)!=string::npos) break;
		  }
		  if (b<26) break;
	  }
		for (c=0;c<26;c++) da[(a*c+b) % 26]=c;
		for (c=0;c<str.size();c++) {
			if (str[c]==' ') cout << ' '; 
			else cout << (char)('a'+da[str[c]-'a']);
		}
        cout << endl;
    n--;
   }
  return 0;
}