import sys N,M,K = map(int,input().split()) lsB = input().split() f = lsB.pop(0) lsB = [int(i) for i in lsB] 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)