n,m,k = map(int,input().split()) B = list(map(str, input().split())) op = B[0] B = [int(i) for i in B[1:]] A = [int(input()) for _ in range(n)] if op=='+': print((sum(B)*n + sum(A)*m)%k) else: ret = 0 sa = sum(A)%k for b in B: ret += (b*sa)%k print(ret%k)