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