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

// エンコード化
bool encode(string from, ref string to, uint alpha, uint beta) {
  uint mask;
  // 重複チェック
  foreach(c; 0..26) {
    mask |= (1 << ((c * alpha + beta) % 26));    
  }
  if (mask != 0x3FFFFFF) return false;
  foreach(c; from) {
    to ~= isAlpha(c) ? ((c - "a"[0]) * alpha + beta) % 26 + "a"[0] : c;
  }
  return true;
}

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..25) {
          string res;
          if (encode(k, res, a, b)) {
            if (res == "that" || res == "this") {
              alpha = a;
              beta = b;
              break;
            }
          }
        }
      }
    }
    string ans;
    encode(line, ans, alpha, beta);
    writeln(ans);
  }
}