n, m, k = map(int, input().split()) opb = list(map(str, input().split())) op = opb[0] b = [int(x) for x in opb[1:]] a = [int(input()) for _ in range(n)] total = 0 if op == '+': total += sum(a) * m % k + sum(b) * n % k total %= k else: sumb = sum(b) % k suma = sum(a) % k total = suma * sumb % k print(total)