// AOJ q0040
// YAMADA Terushige
// 2013.5.6

#include<iostream>
#include<sstream>
#include<string>
#include<cctype>
 
using namespace std;
const int N = 26;

char decode(const char c,const int a,const int b){
  if(islower(c)){
    //    int t = ((c - 'a') + N - b)%N;
    int t = c - 'a' - b;
    while(t%a != 0){
      t += N;
    }
    return 'a' + ((t/a) % N) ;
  }
  return c;
}

int gcm(int a,int b){
  if (b==0) return a;
  else return gcm(b,a%b);
}
 
int main(){
  string s,wd;
  int n;
  cin >> n;
  getline(cin,s);
  int a,b;

  for(int i=0;i<n;i++){
    getline(cin,s);
    string ans = s;
    istringstream istr;
    istr.str(s);
    while(istr >> wd){
      if(wd.size()==4){
	string dd = wd;
	for(a=1;a<N;a++){
	  if(gcm(a,N) != 1) continue;
	  for(b=0;b<N;b++){
	    for(int j=0;j<4;j++)
	      dd[j] = decode(wd[j],a,b);
	    if(dd == "this" || dd == "that")
	      goto solved;
	  }
	}
      }
    }
  solved:
    //    istr.clear();
    for(int k=0;k<s.size();k++)
      ans[k]=decode(s[k],a,b);
    cout << ans << endl;
  }
}
