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 %= 10**9+7 else: c += i+j print (c%k)