Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position".

Watto has already compiled the mechanism, all that's left is to write a program for it and check it on the data consisting of n initial lines and m queries. He decided to entrust this job to you.


-----Input-----

The first line contains two non-negative numbers n and m (0 ≤ n ≤ 3·10^5, 0 ≤ m ≤ 3·10^5) — the number of the initial strings and the number of queries, respectively.

Next follow n non-empty strings that are uploaded to the memory of the mechanism.

Next follow m non-empty strings that are the queries to the mechanism.

The total length of lines in the input doesn't exceed 6·10^5. Each line consists only of letters 'a', 'b', 'c'.


-----Output-----

For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes).


-----Examples-----
Input
2 3
aaaaa
acacaca
aabaa
ccacacc
caaac

Output
YES
NO
NO

Source: codeforces | Difficulty: HARD
Tags: String algorithms

Sorting

Data structures


Solutions:
(n, m) = map(int, input().split())
mod = 9999999999999983
v = set()
for i in range(n):
	s = input()
	l = len(s)
	pow = 1
	h = 0
	for i in range(l):
		h = (h + ord(s[i]) * pow) % mod
		pow = pow * 203 % mod
	pow = 1
	for i in range(l):
		for j in range(97, 100):
			if ord(s[i]) != j:
				v.add((h + (j - ord(s[i])) * pow) % mod)
		pow = pow * 203 % mod
ans = []
for i in range(m):
	s = input()
	pow = 1
	h = 0
	for i in range(len(s)):
		h = (h + ord(s[i]) * pow) % mod
		pow = pow * 203 % mod
	ans.append('YES' if h in v else 'NO')
print('\n'.join(ans))


import sys
u = []
t = set()
p1 = 127
m1 = 1000000007
p2 = 131
m2 = 1000000009
pow1 = [1] + [0] * 600005
pow2 = [1] + [0] * 600005
for i in range(1, 600005):
	pow1[i] = pow1[i - 1] * p1 % m1
	pow2[i] = pow2[i - 1] * p2 % m2

def hash1(n):
	hsh = 0
	for i in range(len(n)):
		hsh += pow1[i] * ord(n[i])
		hsh %= m1
	return hsh % m1

def hash2(n):
	hsh = 0
	for i in range(len(n)):
		hsh += pow2[i] * ord(n[i])
		hsh %= m2
	return hsh % m2
(a, b) = map(int, sys.stdin.readline().split())

def trans(n):
	a = hash1(n)
	b = hash2(n)
	cyc = ['a', 'b', 'c']
	for i in range(len(n)):
		for x in range(3):
			if cyc[x] == n[i]:
				h11 = a - ord(n[i]) * pow1[i] + ord(cyc[(x + 1) % 3]) * pow1[i]
				h12 = b - ord(n[i]) * pow2[i] + ord(cyc[(x + 1) % 3]) * pow2[i]
				h21 = a - ord(n[i]) * pow1[i] + ord(cyc[(x + 2) % 3]) * pow1[i]
				h22 = b - ord(n[i]) * pow2[i] + ord(cyc[(x + 2) % 3]) * pow2[i]
				t.add(h11 % m1 * m2 + h12 % m2)
				t.add(h21 % m1 * m2 + h22 % m2)
for i in range(a):
	trans(sys.stdin.readline())
for j in range(b):
	inpt = sys.stdin.readline()
	if hash1(inpt) * m2 + hash2(inpt) in t:
		print('YES')
	else:
		print('NO')


from sys import stdin
from functools import reduce
from collections import defaultdict
data = stdin.read().split('\n')
(n, m) = [int(x) for x in data[0].split()]
B = 10007
MOD = 1000000000000000003
h = lambda s: reduce(lambda s, c: (B * s + ord(c)) % MOD, s, 0)
hs = defaultdict(set)

def insert(s):
	hs[len(s)].add(h(s))

def find(s):
	v = h(s)
	b = 1
	for c in reversed(s):
		for d in 'abc':
			if c != d:
				u = (v - b * ord(c) + b * ord(d)) % MOD
				if u in hs[len(s)]:
					return True
		b *= B
		b %= MOD
	return False
for i in range(n):
	s = data[i + 1]
	insert(s)
buf = []
for i in range(m):
	s = data[i + n + 1]
	buf.append('YES' if find(s) else 'NO')
print('\n'.join(buf))


con = 1000000000000000009

def Hash(s):
	h = 0
	p = 1
	for c in s:
		h = (h + p * ord(c)) % con
		p = p * 197 % con
	return h
(n, m) = map(int, input().split())
a = set()
for i in range(n):
	s = input()
	h = Hash(s)
	p = 1
	for j in range(len(s)):
		for k in range(97, 100):
			if ord(s[j]) != k:
				a.add((h + p * (k - ord(s[j]))) % con)
		p = p * 197 % con
ans = []
for i in range(m):
	s = input()
	b = Hash(s)
	if b in a:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


from collections import defaultdict
from math import ceil, floor
import sys
memory = set()
mod = 1000000000000000003
p = 3

def hash_(s):
	pp = p
	result = 0
	for ch in s:
		result += pp * (ord(ch) - ord('a') - 1)
		pp = pp * p % mod
		result %= mod
	return result % mod

def find(q):
	hash_0 = hash_(q)
	k = len(q)
	pw = p
	ext = 0
	for j in range(len(q)):
		for ch in 'abc':
			if ch != q[j]:
				if (hash_0 % mod + (ord(ch) - ord(q[j])) * pw % mod) % mod in memory:
					sys.stdout.write('YES\n')
					ext = 1
					break
		if ext:
			break
		pw = p * pw % mod
	if not ext:
		sys.stdout.write('NO\n')

def main():
	(n, m) = [int(i) for i in input().split()]
	for i in range(n):
		memory.add(hash_(sys.stdin.readline().strip()))
	for i in range(m):
		find(sys.stdin.readline().strip())

def __starting_point():
	main()
__starting_point()


[n, m] = [int(i) for i in input().split()]
v = set()
M = 9999999999999983
for i in range(n):
	s = input()
	l = len(s)
	[haf, hb] = [0, 1]
	for j in range(l):
		haf = (haf + hb * ord(s[j])) % M
		hb = hb * 131 % M
	hb = 1
	for k in range(l):
		for j in range(97, 100):
			if ord(s[k]) != j:
				v.add((haf + hb * (j - ord(s[k]))) % M)
		hb = hb * 131 % M
ans = []
for i in range(m):
	s = input()
	hb = 1
	haf = 0
	for j in range(len(s)):
		haf = (haf + hb * ord(s[j])) % M
		hb = hb * 131 % M
	ans.append('YES' if haf in v else 'NO')
print('\n'.join(ans))


from sys import stdin
from collections import defaultdict
from time import time
P = 829
MOD = 2233333333333

def hashing(s, P, MOD):
	h = 0
	b = 1
	for i in s:
		h += b * ord(i)
		h %= MOD
		b *= P
		b %= MOD
	return h

def determine(w, lw):
	return hashing(w, P, MOD) in mem[lw]
chars = ['a', 'b', 'c']
(n, m) = list(map(int, input().split()))
S = time()
mem = defaultdict(set)
for i in range(n):
	t = input()
	h0 = hashing(t, P, MOD)
	lt = len(t)
	b = 1
	for j in range(lt):
		for c in chars:
			if not t[j] == c:
				mem[lt].add((h0 + b * (ord(c) - ord(t[j]))) % MOD)
		b *= P
		b %= MOD
prt = []
for i in range(m):
	w = input()
	lw = len(w)
	if lw not in mem:
		prt.append('NO')
		continue
	if determine(w, lw):
		prt.append('YES')
	else:
		prt.append('NO')
print('\n'.join(prt))


M = 99999999999983

def Hash(s):
	h = 0
	p = 1
	for c in s:
		h = (h + p * (ord(c) - 94)) % M
		p = p * 17 % M
	return h
(n, m) = map(int, input().split())
a = set()
for i in range(n):
	s = input()
	h = Hash(s)
	p = 1
	for j in range(len(s)):
		for k in range(97, 100):
			if ord(s[j]) != k:
				a.add((h + p * (k - ord(s[j]))) % M)
		p = p * 17 % M
ans = []
for i in range(m):
	s = input()
	b = Hash(s)
	if b in a:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


__author__ = 'Utena'
M = 100000000000007

def hash(x):
	a = 0
	for j1 in x:
		a = (a * 1003 + ord(j1)) % M
	return a

def get(q):
	l = len(q)
	e = 1
	h = hash(q)
	for j in range(1, l + 1):
		aj = q[-j]
		(a, b, c) = ((h + e * (ord('a') - ord(aj)) + M * 2) % M, (h + e * (ord('b') - ord(aj)) + M * 2) % M, (h + e * (ord('c') - ord(aj)) + M * 2) % M)
		e = e * 1003 % M
		if aj == 'a':
			if b in search[l] or c in search[l]:
				return 'YES'
		elif aj == 'b':
			if a in search[l] or c in search[l]:
				return 'YES'
		elif aj == 'c':
			if a in search[l] or b in search[l]:
				return 'YES'
	return 'NO'
ans = []
(n, m) = map(int, input().split())
search = [set() for i in range(600001)]
for i in range(n):
	s = input()
	search[len(s)].add(hash(s))
for i in range(m):
	q = input()
	ans.append(get(q))
print('\n'.join(ans))


def init():
	f[0] = 1
	for i in range(1, L):
		f[i] = f[i - 1] * a % table_size

def polyHash(keys):
	hashValue = 0
	for i in range(len(keys)):
		hashValue = (hashValue * a + ord(keys[i]) - 97) % table_size
	return hashValue

def check(query):
	h = polyHash(query)
	leng = len(query)
	for i in range(leng):
		for c in range(3):
			c_char = chr(ord('a') + c)
			if c_char == query[i]:
				continue
			new_hashValue = ((ord(c_char) - ord(query[i])) * f[leng - i - 1] % table_size + table_size + h) % table_size
			if new_hashValue in dic:
				return True
	return False
L = 1000001
table_size = int(1000000000.0) + 7
a = 257
f = [0] * L
init()
(n, m) = map(int, input().split())
dic = set()
for i in range(n):
	keys = input()
	dic.add(polyHash(keys))
buf = []
for i in range(m):
	t = input()
	buf.append('YES' if check(t) else 'NO')
print('\n'.join(buf))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 9999999999999983
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def shash(s):
	ans = 0
	cur = 1
	P = 203
	for i in s:
		ans = (ans + cur * ord(i)) % MOD
		cur = cur * P % MOD
	return ans
(n, m) = I()
stings = set()
for i in range(n):
	s = input()
	stings.add(shash(s))
for i in range(m):
	s = input()
	h = shash(s)
	ans = 'NO'
	cur = 1
	P = 203
	for i in s:
		for j in range(97, 100):
			if ord(i) == j:
				continue
			ok = (h + (j - ord(i)) * cur % MOD) % MOD
			if ok in stings:
				ans = 'YES'
				break
		cur = cur * P % MOD
	print(ans)


(n, m) = [int(i) for i in input().split()]
memory = set()
d = 31918781974729
ans = [None] * m

def Hash(x):
	t = 0
	mul = 1
	for char in x:
		t = (t + ord(char) * mul) % d
		mul = mul * 2193 % d
	return t
for i in range(n):
	string = input()
	t = Hash(string)
	mul = 1
	for j in range(len(string)):
		for char in 'abc':
			if string[j] != char:
				memory.add((t + (ord(char) - ord(string[j])) * mul) % d)
		mul = mul * 2193 % d
for i in range(m):
	string = input()
	t = Hash(string)
	if t in memory:
		ans[i] = 'YES'
	else:
		ans[i] = 'NO'
print(*ans, sep='\n')


M = 9999999999879998

def str_hash(s):
	h = 0
	p = 1
	for c in s:
		h = (h + p * ord(c)) % M
		p = p * 197 % M
	return h
(n, m) = [int(i) for i in input().split()]
a = set()
for i in range(n):
	s = input()
	h = str_hash(s)
	p = 1
	for j in range(len(s)):
		for k in range(97, 100):
			if ord(s[j]) != k:
				a.add((h + p * (k - ord(s[j]))) % M)
		p = p * 197 % M
ans = []
for i in range(m):
	s = input()
	b = str_hash(s)
	if b in a:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


M = 9999999999879998

def myhash(target):
	h = 0
	p = 1
	for j in target:
		h = (h + p * ord(j)) % M
		p = p * 197 % M
	return h

def binarysearch(base, tar):
	low = 0
	high = len(base) - 1
	while low <= high:
		mid = (low + high) // 2
		midval = base[mid]
		if midval > tar:
			high = mid - 1
		elif midval < tar:
			low = mid + 1
		else:
			return 1
	return 0
(n, m) = [int(i) for i in input().split()]
hashval = list()
ans = list()
for i in range(n):
	ini = input()
	h = myhash(ini)
	p = 1
	for j in range(len(ini)):
		for k in range(97, 100):
			if ini[j] != chr(k):
				hashval.append((h + p * (k - ord(ini[j]))) % M)
		p = p * 197 % M
hashval.sort()
for i in range(m):
	query = input()
	hashtem = myhash(query)
	if binarysearch(hashval, hashtem):
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


seed = 201
div = 9999999999999983
ABC = ['a', 'b', 'c']

def hashi(s):
	L = len(s)
	h = 0
	pseed = 1
	for i in range(L):
		(h, pseed) = ((h + ord(s[i]) * pseed) % div, pseed * seed % div)
	return h
(n, m) = [int(c) for c in input().split()]
S = set()
for _ in range(n):
	s = input()
	L = len(s)
	hashs = hashi(s)
	pseed = 1
	for i in range(L):
		orig = s[i]
		for c in ABC:
			if c == orig:
				continue
			S.add((hashs + pseed * (ord(c) - ord(orig)) + div) % div)
		pseed = pseed * seed % div
res = []
for _ in range(m):
	hi = hashi(input())
	if hi in S:
		res.append('YES')
	else:
		res.append('NO')
print('\n'.join(res))


modValue = 9999999999999983

def Hash(s):
	hash = 0
	p = 1
	for char in s:
		hash = (hash + p * (ord(char) - 94)) % modValue
		p = p * 197 % modValue
	return hash
(n, m) = map(int, input().split())
a = set()
for i in range(n):
	string = input()
	hash = Hash(string)
	p = 1
	for j in range(len(string)):
		for k in range(97, 100):
			if ord(string[j]) != k:
				a.add((hash + p * (k - ord(string[j]))) % modValue)
		p = p * 197 % modValue
answer = []
for i in range(m):
	string = input()
	hash = Hash(string)
	if hash in a:
		answer.append('YES')
	else:
		answer.append('NO')
print('\n'.join(answer))


import os
import sys
from io import BytesIO, IOBase
_print = print
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())
(_HASH_A, _HASH_B) = (79, 46)
_HASH_MOD = 10 ** 9 + 7

def multi_hash(hash_func, mod_list=(10 ** 4 + 7, 10 ** 8 + 7, 10 ** 9 + 7)):

	def new_func(*args, **kwargs):
		result = [hash_func(*args, mod=mod, **kwargs) for mod in mod_list]
		if type(result[0]) is int:
			return tuple(result)
		return list(zip(*result))
	return new_func

@multi_hash
def full_hash(s: str, a=_HASH_A, b=_HASH_B, mod=_HASH_MOD) -> int:
	h = 0
	for c in map(ord, s):
		h = (h * a + c - b) % mod
	return h

@multi_hash
def replace_one_hash(s: str, a=_HASH_A, b=_HASH_B, mod=_HASH_MOD):
	n = len(s)
	full = [1] * n
	for i in reversed(range(n - 1)):
		full[i] = full[i + 1] * a % mod
	for (i, c) in enumerate(map(ord, s)):
		full[i] *= c - b
	full_h = sum(full) % mod
	return [(full_h - h) % mod for h in full]

def main():
	(n, q) = mpint()
	d = {}
	for _ in range(n):
		s = inp()
		full_h = full_hash(s)
		for h in replace_one_hash(s):
			if h in d:
				if d[h] != full_h:
					d[h] = -1
			else:
				d[h] = full_h
	for _ in range(q):
		s = inp()
		full_h = full_hash(s)
		for h in replace_one_hash(s):
			if h in d:
				if d[h] == full_h:
					continue
				print('YES')
				break
		else:
			print('NO')
DEBUG = 0
URL = 'https://codeforces.com/contest/514/problem/C'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 2:
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG:

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


import sys
input = sys.stdin.readline
N = int(600000.0 + 5)
m1 = int(1000000000.0 + 7)
m2 = int(1000000000.0 + 9)
pow1 = [1] + [0] * N
pow2 = [1] + [0] * N
for i in range(1, N):
	pow1[i] = pow1[i - 1] * 127 % m1
	pow2[i] = pow2[i - 1] * 131 % m2

def hash1(s):
	res = 0
	for i in range(len(s)):
		res = (res + pow1[i] * ord(s[i]) % m1) % m1
	return res

def hash2(s):
	res = 0
	for i in range(len(s)):
		res = (res + pow2[i] * ord(s[i]) % m2) % m2
	return res
t = set()

def add_str(n):
	a = hash1(n)
	b = hash2(n)
	cyc = ['a', 'b', 'c']
	for i in range(len(n)):
		for j in range(3):
			if cyc[j] != n[i]:
				continue
			x = ord(n[i])
			y = ord(cyc[(j + 1) % 3])
			z = ord(cyc[(j + 2) % 3])
			h11 = a - x * pow1[i] + y * pow1[i]
			h12 = b - x * pow2[i] + y * pow2[i]
			h21 = a - x * pow1[i] + z * pow1[i]
			h22 = b - x * pow2[i] + z * pow2[i]
			t.add(h11 % m1 * m2 + h12 % m2)
			t.add(h21 % m1 * m2 + h22 % m2)
(a, b) = map(int, input().split())
arr = [input() for _ in range(a)]
for s in arr:
	add_str(s)
arr = [input() for _ in range(b)]
res = []
for s in arr:
	res += ['YES' if hash1(s) * m2 + hash2(s) in t else 'NO']
print('\n'.join(res))


from sys import stdin
SMALL_P1 = 127
SMALL_P2 = 131
LARGE_P1 = int(1000000000.0 + 7)
LARGE_P2 = int(1000000000.0 + 9)
MAX_N = int(600000.0 + 5)
powers1 = [0 for i in range(MAX_N)]
powers2 = [0 for i in range(MAX_N)]
powers1[0] = 1
powers2[0] = 1
for i in range(1, MAX_N):
	powers1[i] = powers1[i - 1] * SMALL_P1 % LARGE_P1
	powers2[i] = powers2[i - 1] * SMALL_P2 % LARGE_P2

def hash_string(string):
	hash_value1 = 0
	hash_value2 = 0
	for i in range(len(string)):
		hash_value1 += ord(string[i]) * powers1[i]
		hash_value1 %= LARGE_P1
		hash_value2 += ord(string[i]) * powers2[i]
		hash_value2 %= LARGE_P2
	return (hash_value1, hash_value2)

def adapted_hash(initial_hash1, initial_hash2, pos, orig, subst):
	hash_1 = initial_hash1 + ord(subst) * powers1[pos] % LARGE_P1 - ord(orig) * powers1[pos] % LARGE_P1
	hash_2 = initial_hash2 + ord(subst) * powers2[pos] % LARGE_P2 - ord(orig) * powers2[pos] % LARGE_P2
	return hash_1 % LARGE_P1 * LARGE_P2 + hash_2 % LARGE_P2
(n, m) = map(int, input().split())
hashes = {}
for _ in range(n):
	string = stdin.readline()
	(initial_hash1, initial_hash2) = hash_string(string)
	for i in range(len(string)):
		curr_c = string[i]
		for poss in ['a', 'b', 'c']:
			if poss != curr_c:
				hashes[adapted_hash(initial_hash1, initial_hash2, i, curr_c, poss)] = True
for _ in range(m):
	curr_string = stdin.readline()
	(hash1, hash2) = hash_string(curr_string)
	if hash1 * LARGE_P2 + hash2 in hashes:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
_print = print
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())
import random
HMOD = 2147483647
HBASE1 = random.randrange(HMOD)
HBASE2 = random.randrange(HMOD)

class Hashing:

	def __init__(self, s, mod=HMOD, base1=HBASE1, base2=HBASE2):
		if type(s) is str:
			s = [c - 46 for c in map(ord, s)]
		(self.mod, self.base1, self.base2) = (mod, base1, base2)
		self._len = _len = len(s)
		(f_hash, f_pow) = ([0] * (_len + 1), [1] * (_len + 1))
		(s_hash, s_pow) = ([*f_hash], [*f_pow])
		for i in range(_len):
			f_hash[i + 1] = (base1 * f_hash[i] + s[i]) % mod
			s_hash[i + 1] = (base2 * s_hash[i] + s[i]) % mod
			f_pow[i + 1] = base1 * f_pow[i] % mod
			s_pow[i + 1] = base2 * s_pow[i] % mod
		(self.f_hash, self.f_pow) = (f_hash, f_pow)
		(self.s_hash, self.s_pow) = (s_hash, s_pow)
		self.full_hash = (ff, sf) = (f_hash[-1], s_hash[-1])
		self.replace_one_hash = [((ff - s[i] * f_pow[_len + ~i]) % mod, (sf - s[i] * s_pow[_len + ~i]) % mod) for i in range(_len)]

def main():
	(n, q) = mpint()
	d = {}
	for _ in range(n):
		hs = Hashing(inp())
		for h in hs.replace_one_hash:
			if h in d:
				if d[h] != hs.full_hash:
					d[h] = -1
			else:
				d[h] = hs.full_hash
	for _ in range(q):
		hs = Hashing(inp())
		for h in hs.replace_one_hash:
			if h in d:
				if d[h] == hs.full_hash:
					continue
				print('YES')
				break
		else:
			print('NO')
DEBUG = 0
URL = 'https://codeforces.com/contest/514/problem/C'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 2:
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG:

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


from sys import stdin
from functools import reduce
from collections import defaultdict
_data = iter(stdin.read().split('\n'))

def input():
	while True:
		return next(_data)

def insert(s):
	hs[len(s)].add(h(s))

def found(s):
	v = h(s)
	b = 1
	for c in reversed(s):
		for d in 'abc':
			if c != d:
				u = (v - b * ord(c) + b * ord(d)) % MOD
				if u in hs[len(s)]:
					return True
		b *= B
		b %= MOD
	return False
(n, m) = [int(x) for x in input().split()]
B = 10007
MOD = 1000000000000000003
h = lambda s: reduce(lambda s, c: (B * s + ord(c)) % MOD, s, 0)
hs = defaultdict(set)
for i in range(n):
	s = input()
	insert(s)
text = []
for i in range(m):
	s = input()
	text.append('YES' if found(s) else 'NO')
print('\n'.join(text))


(n, m) = [int(i) for i in input().split()]
memory = set()
M = 99999923990274967
d = 2193
for i in range(n):
	s = input()
	t = 0
	p = 1
	for char in s:
		t = (t + ord(char) * p) % M
		p = p * d % M
	p = 1
	for j in range(len(s)):
		for k in range(97, 100):
			if ord(s[j]) != k:
				memory.add((t + (k - ord(s[j])) * p) % M)
		p = p * d % M
answer = []
for i in range(m):
	s = input()
	t = 0
	p = 1
	for char in s:
		t = (t + ord(char) * p) % M
		p = p * d % M
	if t in memory:
		answer.append('YES')
	else:
		answer.append('NO')
print('\n'.join(answer))


N = 9999999999999999999999999999999999999984
(n, m) = tuple(map(int, input().split()))
memory = set()
for _ in range(n):
	su = 0
	p = 1
	entry = input()
	for letter in entry:
		su = (su + p * ord(letter)) % N
		p = p * 203 % N
	p = 1
	for letter in entry:
		for i in ['a', 'b', 'c']:
			if i != letter:
				memory.add((p * (ord(i) - ord(letter)) + su) % N)
		p = p * 203 % N
answer = []
for _ in range(m):
	su = 0
	p = 1
	for letter in input():
		su = (su + p * ord(letter)) % N
		p = p * 203 % N
	if su in memory:
		answer.append('YES')
	else:
		answer.append('NO')
print('\n'.join(answer))


from sys import stdin, stdout
N = 600000 + 2
p = [0] * N
MOD = 9999999999999983

def populate_powers():
	p[0] = 1
	for i in range(1, N):
		p[i] = p[i - 1] * 203 % MOD

def get_hash(s):
	val = 0
	i = 0
	for c in s:
		val += ord(c) * p[i] % MOD
		i += 1
	return val

def main():
	populate_powers()
	(n, m) = [int(_) for _ in input().split()]
	d = {}
	for i in range(n):
		s = stdin.readline()
		d[get_hash(s)] = 1
	result = []
	for i in range(m):
		s = stdin.readline()
		ans = 'NO'
		v1 = get_hash(s)
		for j in range(len(s)):
			for x in 'abc':
				if x == s[j]:
					continue
				v2 = v1 - ord(s[j]) * p[j] % MOD + ord(x) * p[j] % MOD
				if v2 in d:
					ans = 'YES'
					break
			if ans == 'YES':
				break
		result.append(ans)
	stdout.write('\n'.join(result))
main()


from sys import stdin, stdout
(a, b) = map(int, input().split())
qw = set()

def hash(st):
	h = 0
	for (l, i) in enumerate(st):
		h += ord(i) * pow(1212121, l, 10 ** 9 + 7)
		h %= 10 ** 9 + 7
	return h
for i in range(a):
	qw.add(hash(stdin.readline().strip()))
for i in range(b):
	er = stdin.readline().strip()
	t = hash(er)
	boo = 0
	for l in range(len(er)):
		xx = pow(1212121, l, 10 ** 9 + 7)
		if er[l] != 'a' and (t + xx * (97 - ord(er[l]))) % (10 ** 9 + 7) in qw:
			boo = 1
			stdout.write('YES\n')
			break
		if er[l] != 'b' and (t + xx * (98 - ord(er[l]))) % (10 ** 9 + 7) in qw:
			boo = 1
			stdout.write('YES\n')
			break
		if er[l] != 'c' and (t + xx * (99 - ord(er[l]))) % (10 ** 9 + 7) in qw:
			boo = 1
			stdout.write('YES\n')
			break
	if boo == 0:
		stdout.write('NO\n')


from collections import defaultdict
(n, M) = map(int, input().split())
m = 99999999999999999999999983
seti = set()
for i in range(n):
	s = input()
	po = 1
	h = 0
	for i in s:
		(h, po) = ((h + ord(i) * po) % m, po * 203 % m)
	po = 1
	for i in range(len(s)):
		for j in range(97, 100):
			if ord(s[i]) != j:
				z = (h % m - ord(s[i]) % m * po % m + j % m * po % m) % m
				seti.add(z % m)
		po = po * 203 % m
po = 1
ans = []
for i in range(M):
	s = input()
	po = 1
	h = 0
	for i in s:
		(h, po) = ((h + ord(i) * po) % m, po * 203 % m)
	if h in seti:
		ans.append('YES')
	else:
		ans.append('NO')
print('\n'.join(ans))


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
pp = 203
qq = 9999999999999983

def h(x):
	som = 0
	p = 1
	for i in range(len(x)):
		som = (som + ord(x[i]) * (p % qq)) % qq
		p = p * pp % qq
	return som
e = set()
e1 = set()
for i in range(n):
	s = input()
	ss = h(s)
	p = 1
	for j in range(len(s)):
		for y in 'abc':
			if s[j] == y:
				continue
			e.add((ss + (ord(y) - ord(s[j])) * p) % qq)
		p = p * pp % qq
aa = []
for i in range(m):
	s = input()
	if h(s) in e:
		aa.append('YES')
	else:
		aa.append('NO')
print('\n'.join(aa))