#Megan Chao

#ACSL Contest #4

#Intermediate-5 Division

#Montgomery Blair High School #2070

 

Code = [" ","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

for input in range (1,6):

    Msg = []

    Encoder = [0]*4

    inputline = raw_input("Input: ")

    start = 0

    for char in range (0,len(inputline)):

        if inputline[char] == ",":

            number = int(inputline[start:char])

            Msg = Msg + [number]

            start = char + 1

    Msg = Msg + [inputline[start:len(inputline)]]

    a = int(Msg[len(Msg)-4])

    b = int(Msg[len(Msg)-3])

    c = int(Msg[len(Msg)-2])

    d = int(Msg[len(Msg)-1])

    Encoder[0] = 1/(a*d-b*c)*d

    Encoder[1] = -1/(a*d-b*c)*b

    Encoder[2] = -1/(a*d-b*c)*c

    Encoder[3] = 1/(a*d-b*c)*a

    num = Msg[0]

    del Msg[0]

    del Msg[len(Msg)-4:len(Msg)]

    Decoder = [0]*len(Msg)

    for pair in range (0,num/2):

        Decoder[2*pair] = Encoder[0]*Msg[pair] + Encoder[1]*Msg[pair+num/2]

        Decoder[2*pair+1] = Encoder[2]*Msg[pair] + Encoder[3]*Msg[pair+num/2]

    Decoded = ""

    for char in Decoder:

        char %= 27

        Decoded += Code[char]

    print Decoded