M,N,mulX,addX,mulY,addY,mod=map(int,input().split()) X=list(map(int,input().split())) Y=list(map(int,input().split())) A=list(map(int,input().split())) B=list(map(int,input().split())) cnt=[0]*mod for x,y in zip(X,Y): cnt[x]+=y for i in range(M,N): x = (x * mulX + addX)&(mod-1) y = (y * mulY + addY)&(mod-1) cnt[x]+=y is_prime=[True]*mod for p in range(2,mod): if is_prime[p]: for x in range((mod-1)//p,0,-1): cnt[x]+=cnt[x*p] for i in range(2*p,mod,p): is_prime[i]=False ans=0 for a,b in zip(A,B): c=0 if a