J=lambda:map(int,input().split()) N,Q=J() for i in[0]*Q:X,*_=J();print("YNeos"[X%N and str(X).find(str(N))<0::2])