tmp = list(map(int, input().split())) N, M, K = tmp[0], tmp[1],tmp[2] tmp = input().split() op, B = tmp[0], [int(s) for s in tmp[1:]] A = [int(input()) for _ in range(N)] tmp = [] if op == '+': print((sum(A)*M + sum(B)*N)%K) if op == '*': print(sum(A)*sum(B)%K)