N,M,K = map(int,input().split()) B = list(input().split()) OP = B[0] B = list(map(int, B[1:])) A = [] for _ in range(N): A.append(int(input())) ANS = 0 if OP=='+': for a in A: ANS = (ANS+a*M)%K for b in B: ANS = (ANS+b*N)%K else: SB = sum(B) for a in A: ANS = (ANS+a*SB)%K print(ANS)