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

void main()
{
    foreach(_; 0 .. readln.chomp.to!int)
    {
        auto line = readln;
        auto keys = line.split.filter!(str => str.length == 4);
        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.decode(a, b);
                    if(decoded == "this" || decoded == "that")
                    {
                        line.decode(a, b).write;
                    }
                }
            }
        }
    }
}

string decode(string encoded, int a, int b)
{
    string decoded;
    foreach(c; encoded)
    {
        if(c.isAlpha)
        {
            decoded ~= (a * (c - 'a') + b) % 26 + 'a';
        }
        else
        {
            decoded ~= c;
        }
    }
    return decoded;
}