ary=[]
alphabet=("a".."z").to_a
a,b=0,0
c=0#???????????????????????????
for i in 1..gets.to_i
    ary=gets.chomp.split(nil)#Sample Input
    th=ary.select {|item| item.size-4==0}
    
    (0..25).select do |alpha|
        (0..25).select do |beta|
            (th.size).times do |i|
                if(alphabet.index(th[i][0].chr))
                    if((alpha*alphabet.index(th[i][0].chr)+beta)%26==19)&&(alphabet.index(th[i][0].chr))#t
                        if((alpha*alphabet.index(th[i][1].chr)+beta)%26==7)&&(alphabet.index(th[i][1].chr))#h
                            if((alphabet.index(th[i][2].chr))&&(alpha*alphabet.index(th[i][2].chr)+beta)%26==0)||((alpha*alphabet.index(th[i][2].chr)+beta)%26==8)#a?????????i
                                c+=1
                                a,b=alpha,beta
                                break
                            end
                        end
                    end
                end
            end
            break if(c==1)
        end
        break if(c==1)
    end
    str2=$_.split(//)
    str2.each do |char|
        if alphabet.index(char)
            print alphabet[(a*alphabet.index(char)+b)%26]
            next
        end
        print char
    end
end