from collections import defaultdict def prime_decomposition(n): i = 2 table = defaultdict(int) while i * i <= n: c = 0 while n % i == 0: n /= i c+=1 if c!=0: table[i] = c i += 1 if n > 1: table[int(n)] = 1 return table N, M, K = map(int, input().split()) R = 0 table = prime_decomposition(K) bs = [] fs = [] bbs = dict() ffs = dict() for i in range(N+1): if i == 0: X = input().split() e = X[0] == '+' if e: d = defaultdict(int) for x in X[1:]: d[K-int(x)%K] += 1 else: bs = list(map(lambda x: prime_decomposition(int(x)), X[1:])) d = defaultdict(int) for b in bs: d[1] += 1 yakusus = [1] for k in b: yn = len(yakusus) for j in range(yn): for l in range(b[k]): yakusus.append(yakusus[j]*(k**(l+1))) d[yakusus[j]*(k**(l+1))] += 1 continue x = int(input()) if e: R += d[x%K] else: fs.append(prime_decomposition(x)) if e: print(R) else: R = 0 for b in fs: r = K for key in b: if key in table: r //= key**min(table[key], b[key]) # print(r, K) R += d[r] # ffs[key].sort() print(R)