import sys,threading input=lambda:sys.stdin.readline().rstrip() x,y,z,w=123456789,362436069,521288629,88675123 mod=100003 def inv(A): rem=mod-2 temp=A ret=1 while rem: if rem%2: ret=(ret*temp)%mod temp=(temp**2)%mod rem>>=1 return ret def calc1(A,Q): ret=0 for i in A: ret=max(ret,(Q*i)%mod) return ret def calc2(B,Q): invQ=inv(Q) for i in range(mod-1,-1,-1): if (i*invQ)%mod in B: return i N,M=map(int,input().split()) A=[0]*N for i in range(N): t=x^((x<<11)%(1<<32)) x,y,z=y,z,w w=w^(w>>19)^(t^(t>>8)) A[i]=w%mod B=set(A) for i in range(M): Q=int(input()) if Q==0: print(0) continue print(calc1(A,Q) if N<100 else calc2(B,Q))