type tree=record next:array['a'..'z']of longint; g:boolean; end;vara:array[1..1000]of tree;i,j,n,m,now,e:longint;s:string;ans:boolean;begin readln(n,m); e:=1; for i:=1 to n do begin readln(s); now:=1; for j:=1 to length(s) do if a[now].next[s[j]]=0 then begin inc(e); a[now].next[s[j]]:=e; now:=e; end else now:=a[now].next[s[j]]; a[now].g:=true; end; for i:=1 to m do begin readln(s); ans:=false; now:=1; for j:=1 to length(s) do if a[now].next[s[j]]<>0 then now:=a[now].next[s[j]]; if a[now].g then writeln('Y') else writeln('N'); end;end.