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

// m < n
int gcd(int m, int n) {
    int t;
    while (m > 0) {
        t = m;
        m = n % m;
        n = t;
    }
    return n;
}


string affine(int a, int b, const string& word) {
    string newword;
    newword.resize(word.size());
    for (int i = 0, l = word.size(); i < l; i++) {
        if ('a' <= word[i] && word[i] <= 'z') {
            newword[i] = ((a * (word[i] - 'a') + b) % 26) + 'a';
        }
        else {
            newword[i] = word[i];
        }
    }
    return newword;
}

int main() {
    int n;
    string line;

    cin >> n;
    cin.ignore();
    while (n--) {
        int a, b;
        bool found_param = false;
        char tbl[26];

        getline(cin, line);
        for (a = 1; a < 26; a++) {
            if (gcd(a, 26) != 1) continue;
            for (b = 0; b < 26; b++) {
                string w1 = affine(a, b, "that");
                string w2 = affine(a, b, "this");
                string::size_type p1 = line.find(w1);
                string::size_type p2 = line.find(w2);
                if (p1 != string::npos || p2 != string::npos) {
                    found_param = true;
                    break;
                }
            }
            if (found_param) break;
        }
        if (!found_param) continue;
        for (int i = 0; i < 26; i++) {
            tbl[(a * i + b) % 26] = i + 'a';
        }
        for (int i = 0, l = line.size(); i < l; i++) {
            if ('a' <= line[i] && line[i] <= 'z') {
                cout << tbl[line[i] - 'a'];
            }
            else {
                cout << line[i];
            }
        }
        cout << endl;
    }
    return 0;
}