R=range I=lambda:map(int,input().split()) T,m=I() P,n=set(),m for i in R(2,min(m+1,31623)): if n%i<1:P.add(i) while n%i<1:n//=i M=[n]*(n>1) def G(a,b): while a:a,b=b%a,a return b def r(n): for j in R(len(M)): while M[j]%n<1:M[j]//=n P.add(n) while M: n=M.pop() c=int(n**0.25)*9 if n<10**9:r(n) else: while c: x,d=c,1 y=(x*x+1)%n while (d<2)*c:x,y,d,c=(x*x+1)%n,(y**4+2*y*y+2)%n,G(abs(x-y),n),c-1 if d>i&1])%2*2for d in R(U)] for t in R(T): N,B,C,D=I() c=[1]*U for a in I(): b=0 for i in R(L):b|=(m//a%P[i]<1)<>i&1<1:c[d]=c[d]*c[d|1<