n,m,k=map(int,input().split()) t=input().split() op=t[0] M=sum(int(i) for i in t[1:]) N=sum(int(input()) for _ in range(n)) if op=='+': print((n*M+m*N)%k) else: print((M*N)%k)