#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>

using namespace std;

int A;
int B;

void th(char before[]){
    int alpha[]={1,3,5,7,9,11,15,17,19,21,23,25};
    int str_int;
    char str[5];
    for(int i=0;alpha[i]<26;i++){
        for(int j=0;j<26;j++){
            for(int k=0;k<4;k++){
                str_int=(int)(before[k]-'a');
                str[k]=(char)((alpha[i]*str_int+j)%26)+'a';
            }
            str[4]='\0';
            if(strcmp(str,"that")==0||strcmp(str,"this")==0){
                A=alpha[i];
                B=j;
                return;
            }
        }
    }
    return;
}

char complex(char before){
    int str_int;
    char str;
    str_int=(int)(before-'a');
    str=(char)((A*str_int+B)%26+'a');
    return (str);
}

int main(void){
    char before[257][257],after[257][257];
    int len;
    int n;
    
    cin>>n;
    for(int l=0;l<n;l++){
    int i=0;
    while(scanf("%s",before[i])){
        if(strlen(before[i])==4){
            th(before[i]);
        }
        i++;
        if(getchar()=='\n')break;
    }
    for(int j=0;j<i;j++){
        len=strlen(before[j]);
        for(int k=0;k<len;k++){
            after[j][k]=complex(before[j][k]);
        }
        after[j][len]='\0';
        printf("%s",after[j]);
        if(j!=i-1)printf(" ");
    }
    printf("\n");
    }
    return(0);
}