N, M, K = map(int, input().split()) B = input().split() op = B.pop(0) B = list(map(int, B)) A = [0] * N for i in range(N): A[i] = int(input()) if op == "+": print((sum(A) * M + sum(B) * N)%K) else: print((sum(A) * sum(B))%K)