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

string convert(int a, int b, string str) {
    for (int i = 0; i < (int)str.length(); ++i) {
        if (str[i] != ' ')
            str[i] = char((a * (str[i] - 'a') + b) % 26 + 'a');
    }
    return str;
}


int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string str;
        getline(cin, str);
        getline(cin, str);
        for (int a = 0; a < 26; ++a) {
            for(int b = 0; b < 26; ++b) {
                string str2;
                stringstream ss;
                ss << convert(a, b, str);
                while (!ss.eof()) {
                    ss >> str2;
                    if (str2 == "this" || str2 == "that") {
                        cout << convert(a, b, str) << endl;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

