n, m, b = map(int, input().split()) ans = 1 for x in map(int, input().split()): ans = ans * (1 + pow(m, x, b)) % b print(ans)