let decrypt str =
  let alpha_l = [1; 3; 5; 7; 9; 11; 15; 17; 19; 21; 23; 25] in (*26*)
  let solve beta =
    let check alpha =
      let f gu =
        let g = (int_of_char gu) - (int_of_char 'a') in
        if g < 0 || g >= 26 then gu else
          let ans = (alpha * g + beta) mod 26 in
          char_of_int (ans + (int_of_char 'a'))
      in
      let conv = String.map f str in
      let rec pad from =
        let next = try String.index_from conv from ' '
                   with Not_found -> String.length conv
        in
        if (next - from = 4) && (let s = String.sub conv from 4 in s = "this" || s = "that") then
          true
        else
          if next <> String.length conv then
            pad (next+1)
          else false
      in
      let res = pad 0 in
      if res then Printf.printf "%s\n" conv;
      res
    in
    List.exists check alpha_l
  in
  let rec rep = function
      26 -> ()
    | n -> if not (solve n) then rep (n+1)
  in
  rep 0

let () =
  let n = read_int () in
  let rec solve = function
      0 -> ()
    | n -> decrypt (read_line ()); solve (n-1)
  in
  solve n