A, B = map(int, input().split())
m = int(input())
A_arr = list(map(int, input().split()))
B_arr = []
# A진법 -> 10진법
decimal = 0
for i in range(m):
decimal += A_arr[m-i-1] * (A ** i)
# 10진법 -> B진법
while decimal != 0:
B_arr.append(decimal%B)
decimal //= B
print(' '.join( list(map(str, B_arr))[::-1] ))