import std.stdio;
import std.string;
import std.conv;
import std.ascii;
import std.algorithm;


void main()
{
    foreach (_; 0..readln.chomp.to!int) {
        auto script = readln;
        auto keys   = script.split.filter!(str => str.length == 4);
    loop:
        foreach (a; [0, 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]) {
            foreach (b; 0..26) {
                foreach (key; keys) {
                    string decoded = key.decrypt(a, b);
                    if (decoded == "this" || decoded == "that") {
                        script.decrypt(a, b).write;
                        break loop;
                    }
                }
            }
        }
    }
}


string decrypt(string input, int a, int b)
{
    string output;
    
    foreach (c; input) {
        output ~= isAlpha(c) ? ((c - 'a') * a + b) % 26 + 'a' : c;
    }

    return output;
}