# Arup Guha
# 9/13/2023
# Example Code to Encrypt via Hill Cipher

def main():

    # build empty key.
    n = int(input())
    key = []
    for i in range(n):
        key.append([])

    # Build the key
    for i in range(n):
        toks = input().split()
        for j in range(n):
            key[i].append(int(toks[j]))

    # get message
    plain = input().strip()

    # Pad with X until the plaintext is a valid length.
    while len(plain)%n != 0:
        plain = plain + "X"

    # Encrypt and print ciphertext!
    cipher = encrypt(key, plain)
    print(cipher)

def encrypt(key, plain):

    res = ""
    n = len(key)
    
    # i will be starting index of each block
    for i in range(0, len(plain), n):
        res = res + encryptBlock(key, plain[i:i+n])
        
    # Ta da!
    return res

# Assume the block is the correct length!
def encryptBlock(key, block):

    res = ""
    n = len(key)

    # Go through each row of the key.
    for i in range(n):

        # Add up our pair products.
        total = 0
        for j in range(n):
            total += key[i][j]*(ord(block[j])-ord('A'))

        # mod and add letter.
        total %= 26
        res = res + chr(total+ord('A'))

    # Ta da!
    return res

# Let's run it!
main()
