import scala.io.StdIn.{readInt,readLine}

object Main {
  val alist = 0 to 25
  val blist = 0 to 99
  val invs = for{
    i<-alist
    j<-1 to 25 by 2
    if (i*j) % 26 == 1
  } yield (i,j)
  def encode(c:Int,a:Int,b:Int) = (((a*(c-97)+b) % 26)+97).toChar
  def decode(c:Int,a:Int,b:Int) = ((a*(c-97-b+26) % 26)+97).toChar

  def main(args:Array[String]) = {
    val n = readInt
    (0 until n).foreach { _ =>
      val l = readLine
      val (a,b) = {for(i<-alist;j<-blist) yield (i,j)}.find{ case (i,j) =>
            l.contains("that".map{encode(_,i,j)}) || l.contains("that".map{encode(_,i,j)})
      }.get
      println( l.map { c=> if(c>=97 && c<=122) decode(c,invs.find(s => s._1 == a).getOrElse((0,0))._2,b) else c })
    }
  }
}