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

// エンコード化
string decrypt(string from, uint alpha, uint beta) {
  string chars;
  foreach(c; from) {
    chars ~= isAlpha(c) ? ((c - "a"[0]) * alpha + beta) % 26 + "a"[0] : c;
  }
  return chars;
}

void main() {
  int times = readln.chomp.to!(int);
  foreach(t; 0..times) {
    string line = readln.chomp;
    string[] keys = line.split(" ").filter!(x => x.length == 4).array;
    foreach(a; [0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) {
      foreach(b; 0..26) {
        foreach(k; keys) {
          string res = decrypt(k, a, b);
          if (res == "that" || res == "this") {
            decrypt(line, a, b).writeln;
            goto end;
          }
        }
      }
    }
  end:;
  }
}