#include <iostream>
#include <cctype>
using namespace std;

string ss, subs[256];
int a, b, n;

bool ifincluded(string trg, string s){
    int count = 0;
    string::iterator ittrg = trg.begin();
    for(string::iterator its = s.begin(); its != s.end(); its++){
        if( *its == *ittrg ){
            ittrg++;
            if( ittrg == trg.end() ){
                return 1;
            }
        }else{
            ittrg = trg.begin();
            if( its == trg.begin() ){
                ittrg++;
            }
        }

    }
    return false;
}

int main(){
    cin >> n;
    getline(cin, ss);
    string THIS("this"), THAT("that");
    while( n-- > 0 ){
        getline(cin, ss);
        string cs;
        bool ok = false;
        for(a = 1; !ok && a < 26; a++){
            if( 26%a == 0 ) continue;
            for(b = 0; !ok && b < 26; b++){
                cs = ss;
                for(string::iterator it = cs.begin(); it != cs.end(); it++){
                    if( isalpha( *it ) ){
                        *it = ( (*it-'a') * a + b) % 26 + 'a'; 
                    }
                }
                if( ifincluded( THIS, cs ) ||
                    ifincluded( THAT, cs ) ){
                    ok = 1;
                }
            }
        }
        cout << cs << endl;
    }
    return 0;
}