import sys input = sys.stdin.readline from collections import defaultdict import fractions N, M, K = map(int, input().split()) R = 0 bs = [] fs = [] 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(int, X[1:])) d = defaultdict(int) for b in bs: b = fractions.gcd(b, K) d[b] += 1 continue x = int(input()) if e: R += d[x%K] else: fs.append(x) if e: print(R) else: d2 = defaultdict(int) for b in fs: b = fractions.gcd(b, K) d2[b] += 1 for c in d: for e in d2: if fractions.gcd(c*e, K) == K: R += d[c]*d2[e] print(R)