#include<iostream>
#include<string>
using namespace std;
 
int a[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
 
void solve(){
   string str;
   getline(cin,str);
 
   int A,B;
   A = B = 0;
    
   for(int i = 0 ; i < 12 ; i++){
      for(int j = 0 ; j < 26 ; j++){
     string tmp = "this";
     for(int k = 0 ; k < 4 ; k++){
        tmp[k] = (a[i]*(tmp[k]-'a')+j)%26 + 'a';
     }
     if(str.find(tmp) != -1){
        A = a[i]; B = j;
        i = 11;j = 26;
        break;
     }
 
     tmp = "that";
     for(int k = 0 ; k < 4 ; k++){
        tmp[k] = (a[i]*(tmp[k]-'a')+j)%26 + 'a';
     }
     if(str.find(tmp) != -1){
        A = a[i]; B = j;
        i = 11;j = 26;
        break;
     }
 
      }
   }
   for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == ' '){
     cout << ' ';
     continue;
      }
      for(int j = 0 ; j < 26 ; j++){
     if(str[i]-'a' == (A*j + B)%26){
        cout << (char)(j + 'a');
        break;
     }
      }
   }
   cout << endl;
}
 
int main(){
   int n;
   cin >> n;
   string tmp;
   getline(cin,tmp);
   for(int i = 0 ; i < n ; i++){
      solve();
   }
   return 0;
}