let split str delim =
  let open String in
  let rec split str acc =
    if str = "" then List.rev acc
    else
      try
        let len = length str in
        let i = index str delim in
        split (sub str (i + 1) (len - i - 1)) ((sub str 0 i)::acc)
      with Not_found -> List.rev (str::acc)
  in split str []

let affine_cipher alpha beta gamma =
  let rotate c =
    if c = ' ' then c
    else
      let offset = int_of_char 'a' in
      char_of_int @@ (alpha * ((int_of_char c) - offset) + beta) mod 26 + offset
  in String.map rotate gamma

let cartesian xs ys =
  let rec cartesian xs ys acc =
    match xs with
    | [] -> acc
    | x::xs ->
       let acc = List.fold_left (fun acc y -> (x, y)::acc) acc ys in
       cartesian xs ys acc
  in List.rev @@ cartesian xs ys []

let contains_word str word = List.exists ((=) word) (split str ' ')

let iota ?(init = 0) ?(step = 1) n =
  let rec iota n i acc =
    if n = 0 then List.rev acc
    else iota (pred n) (i + step) (i::acc) in
  iota n init []

let () =
  let n = int_of_string @@ read_line () in
  let params = cartesian [3; 5; 7; 9; 11; 15; 17; 19; 21; 23; 25] (iota 26) in
  for i = 1 to n do
    let line = read_line () in
    print_endline @@
      List.find
        (fun s -> contains_word s "this" || contains_word s "that")
        (List.map (fun (alpha, beta) -> affine_cipher alpha beta line) params)
  done