def main(): import sys input = sys.stdin.readline N, M, K = map(int, input().split()) line = list(input().split()) op = line[0] B = list(map(int, line[1:])) A = [0] * N for i in range(N): A[i] = int(input()) if op == '+': SA = 0 for a in A: SA = (SA + a)%K SB = 0 for b in B: SB = (SB + b) % K print(((SA * M)%K + (SB * N)%K)%K) else: SA = 0 for a in A: SA = (SA + a) % K SB = 0 for b in B: SB = (SB + b) % K print((SA * SB)%K) if __name__ == '__main__': main()