#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<cctype>
#include<cstdlib>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const int N = 26;

int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

map<char, char> makeMap(int a, int b){
    map<char, char> ret;
    REP(i, N){
        char bef = 'a' + i;
        char aft = 'a' + ((a * i + b) % N);
        ret[bef] = aft;
    }
    return ret;
}

bool isAns(string str){
    vector<string> v;
    stringstream ss(str);
    string tmp;
    while(getline(ss, tmp, ' ')) v.push_back(tmp);
    REP(i, v.size()) if(v[i] == "that" || v[i] == "this") return true;
    return false;
}

string findAns(string str){
    if(isAns(str)) return str;
    FOR(a, 1, N){
        if(gcd(N, a) != 1) continue;
        FOR(b, 1, N){
            map<char, char> m = makeMap(a, b);
            string tmp = str;
            REP(i, tmp.length()) if(isalpha(tmp[i])) tmp[i] = m[tmp[i]];
            if(isAns(tmp)) return tmp;
        }
    }
    return "error";
}


int main(){
    int n; cin >>n;
    string str;
    getline(cin, str);
    REP(z, n){
        getline(cin, str);
        cout <<findAns(str) <<endl;
    }
    return 0;
}