import numpy as np n, m, k = map(int, input().split()) op, *element = input().split() array = np.array([int(ele) for ele in element], dtype=np.int64) res = 0 for _ in range(n): num = int(input()) if op == '+': res += np.sum(array+num) elif op == '*': res += np.sum(array*num) print(res%k)