from collections import Counter import math n,m,k,op,*ab = open(0).read().split() m,k = int(m),int(k) f = math.gcd if op=="x" else lambda x,y:y%x a = Counter(f(k,int(i)) for i in ab[:m]) b = Counter(f(k,int(i)) for i in ab[m:]) print(sum(b[-i%k] for i,v in a.items()) if op == "+" else sum(v*w*(i*j%k==0) for j,w in b.items() for i,v in a.items()))