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

// エンコード化
string encode(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;
    int alpha, beta;
    foreach(k; keys) {
      foreach(a; [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) {
        foreach(b; 0..1024) {
          string res = encode(k, a, b);
          if (res == "that" || res == "this") {
            alpha = a;
            beta = b;
            break;
          }
        }
      }
    }
    encode(line, alpha, beta).writeln;
  }
}