n, m, k = map(int, input().split()) bw = list(map(str, input().split())) a = [int(input()) for i in range(n)] op = bw.pop(0) b = [int(i) for i in bw] c = 0 for i in a: for j in b: if op == "*": c += i*j c %= k else: c += i+j c %= k print (c)