# Arup Guha
# 11/11/2025
# Code to decrypt CIS 3362 Homework 6, Question 3

'''
Note: The write up describes how the value of d was determined.
      In this program I've hard-coded the correct value.
'''

# We have to convert from a number to a radix 64 character.
def radixBack(num):
    if num < 26:
        return chr(num+ord('A'))
    elif num < 52:
        return chr(num-26+ord('a'))
    elif num < 62:
        return chr(num-52+ord('0'))
    elif num == 62:
        return '+'
    else:
        return '/'

# This does the conversion.
def convertBack(msg, blocksize):

    res = ""

    # Concatenate letters from back to front.
    for i in range(blocksize):
        let = radixBack(msg%64)
        res = let + res
        msg = msg//64

    # Ta da!
    return res

# Given public key.
n = 1535351991891555110540094304098683022660028069757977

# How we can determine the blocksize.
blocksize = 0
while 64**blocksize < n:
    blocksize += 1
blocksize -= 1

# Value of d we figured out.
d = 888247211109765275577014842192813928278834018093703

# I just counted this from the assignment.
BLOCKS = 9

# Loop through each block
for i in range(BLOCKS):

    # Read cipher text.
    cipher = int(input())

    # Get the numerical message.
    numMsg = pow(cipher, d, n)
    print(convertBack(numMsg, blocksize))
