N, M, K = map(int,input().split()) B = input().split() s = sum([int(B[l]) for l in range(1,M+1)]) ans = 0 if B[0] == "*": for k in range(N): A = int(input()) ans += s*A ans %= K else: t = 0 for k in range(N): t += int(input()) ans = (s*N+t*M)%K print(ans)