#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string affine(string s, int alpha, int beta){
    int n = s.size();
    for(int i=0; i<n; ++i){
        if('a' <= s[i] && s[i] <= 'z')
            s[i] = ((alpha * (s[i]-'a') + beta) % 26) + 'a';
    }
    return s;
}

int main()
{
    int n;
    cin >> n;
    cin.ignore();

    while(--n >= 0){
        string s;
        getline(cin, s);

        for(int a=1; a<26; ++a){
            for(int b=0; b<26; ++b){
                string s1 = affine("that", a, b);
                string s2 = affine("this", a, b);
                if(s.find(s1) != string::npos || s.find(s2) != string::npos){
                    string to(26, ' ');
                    for(int i=0; i<26; ++i)
                        to[i] = i + 'a';
                    to = affine(to, a, b);
                    string from(26, ' ');
                    for(int i=0; i<26; ++i)
                        from[to[i]-'a'] = i + 'a';


                    for(unsigned i=0; i<s.size(); ++i){
                        if('a' <= s[i] && s[i] <= 'z')
                            s[i] = from[s[i]-'a'];
                    }
                    cout << s << endl;
                }
            }
        }
    }
}