import sys

a = int(sys.argv[1]) #first command line argument
b = int(sys.argv[2]) #second command line arg
n = int(sys.argv[3]) #third command line arg
plaintext = (sys.argv[4]).uppercase #fourth command line arg
ciphertextint = []
ciphertext = []
#convert ascii plaintext to ints, then to cipher text, with integer operations
for c in plaintext:
	x = (ord(c) - 65)
	x *= a
	x += b
	x = x % n
	ciphertextint.append(x)
#convert integer ciphertext back to ascii characters
for x in ciphertextint:
	ciphertext.append(chr(x + 65))

print("".join(ciphertext))