import sys N,M,K = map(int,input().split()) S = input() f = S[0] lsB = list(map(int,S[1:].split())) lsA = [int(input()) for i in range(N)] lsans = [[0]*(M) for i in range(N)] if f == '*': sumB = sum(lsB)%K ans = 0 for i in range(N): ans += lsA[i]*sumB ans %= K print(ans) else: sumB = sum(lsB)%K sumA = sum(lsA)%K sumB *= N sumB %= K sumA *= M sumA %= K print((sumA+sumB)%K)