import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    private boolean isLocalJudgment = false;
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = in.nextInts(n);
        long answer = 0;
        if (k == 1) {
            for (int i : a) {
                if (i == 1) {
                    answer++;
                }
            }
        } else {
            Map<Long, Integer> cnt = new TreeMap<>();
            cnt.put(0L, 1);
            long cur = 0;
            for (int e : a) {
                cur += e;
                long p = 1;
                while (Math.abs(p) <= (long) 1e16) {
                    answer += cnt.getOrDefault(cur - p, 0);
                    p *= k;
                }
                cnt.put(cur, 1 + cnt.getOrDefault(cur, 0));
            }
        }
        out.println(answer);
    }

    private void print(Set<String> toKill) {
        for (String s : toKill) {
            out.print(s);
            out.print(' ');
        }
        out.println();
    }

    private void run() throws IOException {
        if (isLocalJudgment) {
            in = new FastScanner("input.txt");
            out = new PrintWriter(new File("output.txt"));
            while (in.hasNext()) {
                solve();
                out.flush();
            }
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out, false);
            solve();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}


import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    private boolean isLocalJudgment = false;
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = in.nextInts(n);
        long answer = 0;
        Map<Long, Integer> cnt = new TreeMap<>();
        cnt.put(0L, 1);
        long cur = 0;
        for (int e : a) {
            cur += e;
            if (k == 1) {
                answer += cnt.getOrDefault(cur - 1, 0);
            } else if (k == -1) {
                answer += cnt.getOrDefault(cur - 1, 0);
                answer += cnt.getOrDefault(cur + 1, 0);
            } else {
                long p = 1;
                while (Math.abs(p) <= (long) 1e16) {
                    answer += cnt.getOrDefault(cur - p, 0);
                    p *= k;
                }
            }
            cnt.put(cur, 1 + cnt.getOrDefault(cur, 0));
        }
        out.println(answer);
    }

    private void print(Set<String> toKill) {
        for (String s : toKill) {
            out.print(s);
            out.print(' ');
        }
        out.println();
    }

    private void run() throws IOException {
        if (isLocalJudgment) {
            in = new FastScanner("input.txt");
            out = new PrintWriter(new File("output.txt"));
            while (in.hasNext()) {
                solve();
                out.flush();
            }
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out, false);
            solve();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}


import java.io.*;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    private boolean isLocalJudgment = false;
    private FastScanner in;
    private PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = in.nextInts(n);
        long answer = 0;
        if (k == 1) {
            for (int i : a) {
                if (i == 1) {
                    answer++;
                }
            }
        } else {
            Map<Long, Integer> cnt = new TreeMap<>();
            cnt.put(0L, 1);
            long cur = 0;
            for (int e : a) {
                cur += e;
                long p = 1;
                while (p <= (long) 1e16) {
                    answer += cnt.getOrDefault(cur - p, 0);
                    p *= k;
                }
                cnt.put(cur, 1 + cnt.getOrDefault(cur, 0));
            }
        }
        out.println(answer);
    }

    private void print(Set<String> toKill) {
        for (String s : toKill) {
            out.print(s);
            out.print(' ');
        }
        out.println();
    }

    private void run() throws IOException {
        if (isLocalJudgment) {
            in = new FastScanner("input.txt");
            out = new PrintWriter(new File("output.txt"));
            while (in.hasNext()) {
                solve();
                out.flush();
            }
        } else {
            in = new FastScanner();
            out = new PrintWriter(System.out, false);
            solve();
        }
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}

class FastScanner {
    private final BufferedReader br;
    private StringTokenizer st;
    private String last;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public FastScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public FastScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken();
    }

    String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }

    String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next().replace(',', '.'));
    }

    double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][];
        for (int i = 0; i < n; i++) {
            arr[i] = nextDoubles(m);
        }
        return arr;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class CF400C {

	public static void main(String[] args) {
		MyScanner reader = new MyScanner();
		int n = reader.nextInt();
		int k = reader.nextInt();
		long count = 0;
		Set<Long> powers = new TreeSet<>();
		long num = 1;
		while (Math.abs(num) <= 1e14) {
			powers.add(num);
			num *= k;
		}
		long dp[] = new long[n + 1];
		int[] affectionVals = new int[n];
		for (int i = 0; i < n; i++) {
			affectionVals[i] = reader.nextInt();
		}
		Map<Long, Integer> sumToCount = new TreeMap<>();
		dp[0] = 0;
		sumToCount.put(dp[0], 1);
		for (int i = 1; i < dp.length; i++) {
			dp[i] = dp[i - 1] + affectionVals[i - 1];
			sumToCount.put(dp[i], sumToCount.getOrDefault(dp[i], 0) + 1);
			for (Long pow : powers) {
				if (sumToCount.containsKey(dp[i] - pow)) {
					count += sumToCount.get(dp[i] - pow);
				}
			}
		}
		System.out.println(count);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class CF400C {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int n = reader.nextInt();
		int k = reader.nextInt();
		long count = 0;
		Set<Long> powers = new TreeSet<>();
		long num = 1;
		while (Math.abs(num) <= 1e16) {
			powers.add(num);
			num *= k;
		}
		long dp[] = new long[n + 1];
		int[] affectionVals = new int[n];
		for (int i = 0; i < n; i++) {
			affectionVals[i] = reader.nextInt();
		}
		HashMap<Long, Integer> sumToCount = new HashMap<>();
		dp[0] = 0;
		sumToCount.put(dp[0], 1);
		for (int i = 1; i < dp.length; i++) {
			dp[i] = dp[i - 1] + affectionVals[i - 1];
			sumToCount.put(dp[i], sumToCount.getOrDefault(dp[i], 0) + 1);
			for (Long pow : powers) {
				if (sumToCount.containsKey(dp[i] - pow)) {
					count += sumToCount.get(dp[i] - pow);
				}
			}
		}
		System.out.println(count);
	}
}


	import java.util.Arrays;
	import java.util.HashMap;
	import java.util.Scanner;
	import java.util.Set;
	import java.util.TreeSet;

	public class CF400C {

		public static void main(String[] args) {
			Scanner reader = new Scanner(System.in);
			StringBuilder sb = new StringBuilder();
			int n = reader.nextInt();
			int k = reader.nextInt();
			Set<Integer> powers = new TreeSet<>();
			long num = 1;
			while (Math.abs(num) <= 1e9) {
				powers.add((int) num);
				num *= k;
			}
			int dp[] = new int[n];

			int[] affectionVals = new int[n];
			for (int i = 0; i < n; i++) {
				affectionVals[i] = reader.nextInt();
			}
			HashMap<Integer, Integer> sumToIndex = new HashMap<>();
			dp[0] = affectionVals[0];
			sumToIndex.put(dp[0], 0);
			for (int i = 1; i < dp.length; i++) {
				dp[i] = dp[i - 1] + affectionVals[i];
				sumToIndex.put(dp[i], i);
			}

			int count = 0;
			for (Integer pow : powers) {
				for (int i = 0; i < dp.length; i++) {
					if (sumToIndex.containsKey(dp[i] + pow)) {
						if (sumToIndex.get(dp[i] + pow) > i)
							count++;
					}
					if (dp[i] == pow)
						count++;
				}
			}
			System.out.println(count);
		}

	}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class CF400C {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = reader.nextInt();
		int k = reader.nextInt();
		Set<Integer> powers = new TreeSet<>();
		long num = 1;
		while (Math.abs(num) <= 1e9) {
			powers.add((int) num);
			num *= k;
		}
		int dp[] = new int[n];

		int[] affectionVals = new int[n];
		for (int i = 0; i < n; i++) {
			affectionVals[i] = reader.nextInt();
		}
		HashMap<Integer, Integer> sumToIndex = new HashMap<>();
		dp[0] = affectionVals[0];
		sumToIndex.put(dp[0], 0);
		for (int i = 1; i < dp.length; i++) {
			dp[i] = dp[i - 1] + affectionVals[i];
			sumToIndex.put(dp[i], i);
		}

		System.out.println(Arrays.toString(dp));
		int count = 0;
		for (Integer pow : powers) {
			for (int i = 0; i < dp.length; i++) {
				if (sumToIndex.containsKey(dp[i] + pow)) {
					if (sumToIndex.get(dp[i] + pow) > i)
						count++;
				}
				if (dp[i] == pow)
					count++;
			}
		}
		System.out.println(count);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class CF400C {

	public static void main(String[] args) {
		MyScanner reader = new MyScanner();
		int n = reader.nextInt();
		int k = reader.nextInt();
		long count = 0;
		Set<Long> powers = new TreeSet<>();
		long num = 1;
		while (Math.abs(num) <= 1e16) {
			powers.add(num);
			num *= k;
		}
		long dp[] = new long[n + 1];
		int[] affectionVals = new int[n];
		for (int i = 0; i < n; i++) {
			affectionVals[i] = reader.nextInt();
		}
		Map<Long, Integer> sumToCount = new TreeMap<>();
		dp[0] = 0;
		sumToCount.put(dp[0], 1);
		for (int i = 1; i < dp.length; i++) {
			dp[i] = dp[i - 1] + affectionVals[i - 1];
			sumToCount.put(dp[i], sumToCount.getOrDefault(dp[i], 0) + 1);
			for (Long pow : powers) {
				if (sumToCount.containsKey(dp[i] - pow)) {
					count += sumToCount.get(dp[i] - pow);
				}
			}
		}
		System.out.println(count);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
const ll x = 4286305;
ll dp[maxk], poww[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unordered_set<ll> uset;
typedef unordered_map<ll, unordered_set<char>> umapc;
typedef unordered_map<ll, unordered_set<int>> umapi;
const int maxk = 500000;
int n, m;
int slen = 0;
const ll p = 1000000007;
uset set1;
umapc mapc;
umapi mapi;
uset set2;
umapc mapc2;
umapi mapi2;
const ll x = 42863052;
const ll x2 = 47825835;
ll dp[maxk], dp2[maxk], poww[maxk], poww2[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2;
        num *= x, num2 *= x2;
        num %= p, num2 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    dp[0] = dp2[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        dp[i] = hash, dp2[i] = hash2;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<pair<ll, char>> set1;
set<ll> setll;
const ll x = 42986309465;
ll dp[maxk], poww[maxk];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    set1.insert({hash, s[0]});
    setll.insert(hash);
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        set1.insert({hash, s[i]});
        setll.insert(hash);
    }
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    if(!set1.count({hash, s[0]}) && setll.count(hash)) {
        cout << "YES\n";
        return;
    }
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        if(!set1.count({hash, s[i]}) && setll.count(hash)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, int> mapi;
const ll x = 4286305;
ll dp[maxk], poww[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 0 : 1);
        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


/*
    Codeforces Problem 514C: Watto and Mechanism (http://codeforces.com/problemset/problem/514/C)
    Author: arvindr9
    In this implementation, a hash of a string A_0 A_1 ... A_k is (A_0 * x^k + A_1 * x^{k - 1} + ... + A_k * x^0) mod p
*/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxk = 1000000; //max value of a string's length
int n, m;
const ll p = 1000000007;
const ll x = 42863052;
const ll x2 = 47825835;
set<ll> set1; //stores hashes from the memory strings
map<ll, set<char>> mapc; //stores the characters that are zeroed to generate each hash during preprocessing
map<ll, set<int>> mapi; //stores the indices of the characters that are zeroed to generate each hash
set<ll> set2;
map<ll, set<char>> mapc2;
map<ll, set<int>> mapi2;
ll h, h2, poww[maxk], poww2[maxk]; //store the hash of each string and the powers of x1 and x2 mod p

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2;
        num *= x, num2 *= x2;
        num %= p, num2 %= p;
    }
}

void constructHashes(string s) {
    int len = s.size();
    h = h2 = s[0] - '0';
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        h = (h * x + c) % p;
        h2 = (h2 * x2 + c) % p;
    }
}

void insertHashes(string s) {
    constructHashes(s);
    int len = s.size();
    for(int i = 0; i < len; i++) {
        ll hash = (h - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //The hash of the string created by setting the ith character to '0'
        ll hash2 = (h2 - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
    }
}

void checkValidity(string s) {
    constructHashes(s);
    int len = s.size();
    for(int i = 0; i < len; i++) {
        ll hash = (h - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (h2 - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        /*the minimum number of distinct characters that should have been zeroed during
        the preprocessing step to generate the hash (this is equal to 2 if there is a memory
        string that is equal to the query string and 1 otherwise).*/
        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
set<ll> set2;
const ll x = 345678894;
const ll x2 = 3;
ll dp[maxk], dp2[maxk], poww[maxk], poww2[maxk];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2;
        num *= x, num2 *= x2;
        num %= p, num2 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = dp2[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    dp[0] = dp2[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        dp[i] = hash, dp2[i] = hash2;
    }
}

void addToHash(string s) {
    constructDp(s);
    int len = s.size();
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    set1.insert(hash), set2.insert(hash2);
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        set1.insert(hash), set2.insert(hash2);
    }
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    if(set1.count(hash) && set2.count(hash2)) {
        cout << "YES\n";
        return;
    }
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        if(set1.count(hash) && set2.count(hash2)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        addToHash(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
set<pair<ll, char>> setc;
set<pair<ll, int>> seti;
const ll x = 4286309465;
ll dp[maxk], poww[maxk];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        setc.insert({hash, s[i]});
        seti.insert({hash, i});
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        if(set1.count(hash) && !(setc.count({hash, s[i]})) && seti.count({hash, i})) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
const ll x = 4286305;
ll dp[maxk], poww[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 0 : 1);
        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unordered_set<ll> uset;
typedef unordered_map<ll, unordered_set<char>> umapc;
typedef unordered_map<ll, unordered_set<int>> umapi;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
int slen = 0;
const ll p = 1000000007;
uset set1;
umapc mapc;
umapi mapi;
uset set2;
umapc mapc2;
umapi mapi2;
uset set3;
umapc mapc3;
umapi mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
set<pair<ll, char>> setc;
set<pair<ll, int>> seti;
const ll x = 4286305;
ll dp[maxk], poww[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        setc.insert({hash, s[i]});
        seti.insert({hash, i});
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        if(set1.count(hash) && !(setc.count({hash, s[i]})) && seti.count({hash, i})) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef set<ll> uset;
typedef map<ll, set<char>> umapc;
typedef map<ll, set<int>> umapi;
const int maxk = 1000000;
int n, m;
int slen = 0;
const ll p = 1000000007;
uset set1;
umapc mapc;
umapi mapi;
uset set2;
umapc mapc2;
umapi mapi2;
const ll x = 42863052;
const ll x2 = 47825835;
ll dp[maxk], dp2[maxk], poww[maxk], poww2[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2;
        num *= x, num2 *= x2;
        num %= p, num2 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    dp[0] = dp2[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        dp[i] = hash, dp2[i] = hash2;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unordered_set<ll> uset;
typedef unordered_map<ll, unordered_set<char>> umapc;
typedef unordered_map<ll, unordered_set<int>> umapi;
const int maxn = 1000000;
const int maxk = 100000;
int n, m;
int slen = 0;
const ll p = 1000000007;
uset set1;
umapc mapc;
umapi mapi;
uset set2;
umapc mapc2;
umapi mapi2;
uset set3;
umapc mapc3;
umapi mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
const ll p = 1000000007;
set<ll> hashset;
const ll x = 345678894;
ll dp[maxk], poww[maxk], inv_pow[maxk];

//hash[l, r] = dp[r] - (dp[l - 1] * poww[k - q])

void printS() {
    cout << "Set:\n";
    for(ll i: hashset) {
        cout << i << " ";
    }
    cout << "\n";
}

void printDp() {
    cout << "Dp:\n";
    for(ll i: dp) {
        cout << i << " ";
    }
    cout << "\n";
}

ll modpow(ll a, int p, ll mod) {
    if(p == 0) {
        return 1;
    }
    ll res = 1;
    while (p >= 1) {
        if (p&1) {
            res = (res * a) % mod;
            p -= 1;
        }
        if(p > 0) res = (res * res) % mod;
        p /= 2;
    }
    return res;
}

void constructPow() {
    ll num = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num;
        num *= x;
        num %= p;
    }
    ll inv = modpow(x, p - 2, p);
    num = 1;
    for(int i = 0; i < maxk; i++) {
        inv_pow[i] = num;
        num *= inv;
        num %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    dp[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        dp[i] = hash;
    }
}

void addToHash(string s) {
    constructDp(s);
    //cout << s << ":\n";
    int len = s.size();
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    //cout << hash << " ";
    hashset.insert(hash);
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        //cout << hash << " ";
        hashset.insert(hash);
    }
    //cout << "\n";

}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p) % p;
    if(hashset.count(hash)) {
        cout << "YES\n";
        return;
    }
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        if(hashset.count(hash)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        addToHash(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }

    // printS();

    // for(int i = 0; i <= 100; i++) {
    //     printf("poww[%d]: %d\n", i, (int)(poww[i]));
    // }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unordered_set<ll> uset;
typedef unordered_map<ll, unordered_set<char>> umapc;
typedef unordered_map<ll, unordered_set<int>> umapi;
const int maxk = 1000000;
int n, m;
int slen = 0;
const ll p = 1000000007;
uset set1;
umapc mapc;
umapi mapi;
uset set2;
umapc mapc2;
umapi mapi2;
const ll x = 42863052;
const ll x2 = 47825835;
ll dp[maxk], dp2[maxk], poww[maxk], poww2[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2;
        num *= x, num2 *= x2;
        num %= p, num2 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    dp[0] = dp2[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        dp[i] = hash, dp2[i] = hash2;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
set<ll> set2;
map<ll, set<char>> mapc2;
map<ll, set<int>> mapi2;
set<ll> set3;
map<ll, set<char>> mapc3;
map<ll, set<int>> mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 1000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
set<ll> set2;
map<ll, set<char>> mapc2;
map<ll, set<int>> mapi2;
set<ll> set3;
map<ll, set<char>> mapc3;
map<ll, set<int>> mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
set<ll> set2;
set<ll> set3;
const ll x = 345678894;
const ll x2 = 832659923;
const ll x3 = 326918739;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] = '0';
    dp[0] = dp2[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void addToHash(string s) {
    constructDp(s);
    int len = s.size();
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    ll hash3 = (dp3[len - 1] - (dp3[0] * poww3[len - 1]) % p + p) % p;
    set1.insert(hash), set2.insert(hash2), set3.insert(hash3);
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        hash3 = (dp3[len - 1] - (dp3[i] * poww3[len - i - 1]) % p + (dp3[i - 1] * poww3[len - i]) % p + p) % p;
        set1.insert(hash), set2.insert(hash2), set3.insert(hash3);
    }
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    ll hash3 = (dp3[len - 1] - (dp3[0] * poww3[len - 1]) % p + p) % p;
    if(set1.count(hash) && set2.count(hash2) && set3.count(hash3)) {
        cout << "YES\n";
        return;
    }
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        hash3 = (dp3[len - 1] - (dp3[i] * poww3[len - i - 1]) % p + (dp3[i - 1] * poww3[len - i]) % p + p) % p;
        if(set1.count(hash) && set2.count(hash2) && set3.count(hash3)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        addToHash(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 1000;
int n, m;
int slen = 0;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
set<ll> set2;
map<ll, set<char>> mapc2;
map<ll, set<int>> mapi2;
set<ll> set3;
map<ll, set<char>> mapc3;
map<ll, set<int>> mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < slen; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    slen = s.size();
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 1000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
map<ll, set<char>> mapc;
map<ll, set<int>> mapi;
set<ll> set2;
map<ll, set<char>> mapc2;
map<ll, set<int>> mapi2;
set<ll> set3;
map<ll, set<char>> mapc3;
map<ll, set<int>> mapi3;
const ll x = 42863052;
const ll x2 = 47825835;
const ll x3 = 83569294;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];
bool print[2];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < maxk; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void insertHashes(string s) {
    constructDp(s);
    int len = s.size();
    //cout << s << ":\n";
    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        set1.insert(hash);
        mapc[hash].insert(s[i]);
        mapi[hash].insert(i);
        set2.insert(hash2);
        mapc2[hash2].insert(s[i]);
        mapi2[hash2].insert(i);
        set3.insert(hash3);
        mapc3[hash3].insert(s[i]);
        mapi3[hash3].insert(i);
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
    }
    //cout << "\n";
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    //cout << s << ":\n";

    for(int i = 0; i < len; i++) {
        ll hash = (dp[len - 1] - ((s[i] - '0') * poww[len - i - 1]) % p + p) % p;
        ll hash2 = (dp2[len - 1] - ((s[i] - '0') * poww2[len - i - 1]) % p + p) % p;
        ll hash3 = (dp3[len - 1] - ((s[i] - '0') * poww3[len - i - 1]) % p + p) % p;
        //cout << hash << ": " << s[i] << ": " << i << ",  ";
        unsigned int req_size = 1 + (mapc[hash].count(s[i]) ? 1 : 0);
        unsigned int req_size2 = 1 + (mapc2[hash2].count(s[i]) ? 1 : 0);
        unsigned int req_size3 = 1 + (mapc3[hash3].count(s[i]) ? 1 : 0);

        if(set1.count(hash) && (mapc[hash].size() >= req_size) && mapi[hash].count(i)
            && set2.count(hash2) && (mapc2[hash2].size() >= req_size2) && mapi2[hash2].count(i)
            && set3.count(hash3) && (mapc3[hash3].size() >= req_size3) && mapi3[hash3].count(i)) { //hash already exists, different characters were used to hash, hashes were done at the same indices. Issue: there exists another string that produces the same hash value when an index is removed.
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        insertHashes(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1000000;
const int maxk = 10000;
int n, m;
const ll p = 1000000007;
set<ll> set1;
set<ll> set2;
set<ll> set3;
const ll x = 345678894;
const ll x2 = 832659923;
const ll x3 = 326918759;
ll dp[maxk], dp2[maxk], dp3[maxk], poww[maxk], poww2[maxk], poww3[maxk];

void constructPow() {
    ll num = 1;
    ll num2 = 1;
    ll num3 = 1;
    for(int i = 0; i < maxk; i++) {
        poww[i] = num, poww2[i] = num2, poww3[i] = num3;
        num *= x, num2 *= x2, num3 *= x3;
        num %= p, num2 %= p, num3 %= p;
    }
}

void constructDp(string s) {
    for(int i = 0; i < 10000; i++) {
        dp[i] = dp2[i] = dp3[i] = 0LL;
    }
    int len = s.size();
    ll hash = s[0] - '0';
    ll hash2 = s[0] - '0';
    ll hash3 = s[0] - '0';
    dp[0] = dp2[0] = dp3[0] = hash;
    for(int i = 1; i < len; i++) {
        ll c = s[i] - '0';
        hash = (hash * x + c) % p;
        hash2 = (hash2 * x2 + c) % p;
        hash3 = (hash3 * x3 + c) % p;
        dp[i] = hash, dp2[i] = hash2, dp3[i] = hash3;
    }
}

void addToHash(string s) {
    constructDp(s);
    int len = s.size();
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    ll hash3 = (dp3[len - 1] - (dp3[0] * poww3[len - 1]) % p + p) % p;
    set1.insert(hash), set2.insert(hash2), set3.insert(hash3);
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        hash3 = (dp3[len - 1] - (dp3[i] * poww3[len - i - 1]) % p + (dp3[i - 1] * poww3[len - i]) % p + p) % p;
        set1.insert(hash), set2.insert(hash2), set3.insert(hash3);
    }
}

void checkValidity(string s) {
    int len = s.size();
    constructDp(s);
    ll hash = (dp[len - 1] - (dp[0] * poww[len - 1]) % p + p) % p;
    ll hash2 = (dp2[len - 1] - (dp2[0] * poww2[len - 1]) % p + p) % p;
    ll hash3 = (dp3[len - 1] - (dp3[0] * poww3[len - 1]) % p + p) % p;
    if(set1.count(hash) && set2.count(hash2) && set3.count(hash3)) {
        cout << "YES\n";
        return;
    }
    for(int i = 1; i < len; i++) {
        hash = (dp[len - 1] - (dp[i] * poww[len - i - 1]) % p + (dp[i - 1] * poww[len - i]) % p + p) % p;
        hash2 = (dp2[len - 1] - (dp2[i] * poww2[len - i - 1]) % p + (dp2[i - 1] * poww2[len - i]) % p + p) % p;
        hash3 = (dp3[len - 1] - (dp3[i] * poww3[len - i - 1]) % p + (dp3[i - 1] * poww3[len - i]) % p + p) % p;
        if(set1.count(hash) && set2.count(hash2) && set3.count(hash3)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    //freopen("C.in", "r", stdin);
    //freopen("C.out", "w", stdout);
    cin >> n >> m;
    constructPow();
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        addToHash(s);
    }
    for(int i = 1; i <= m; i++) {
        string s;
        cin >> s;
        checkValidity(s);
    }
}


#include <bits/stdc++.h>

using namespace std;

map <string, int> M;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    string s;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M[s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
vector <string> V;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1, C[3];
    C[0] = 'a';
    C[1] = 'b';
    C[2] = 'c';
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
        V.push_back(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        if (n < 2)
        {
            g = 1;
            if (s == V[0])
            {
                cout << "NO" << "\n";
            }
            else if (s.length() == V[0].length())
            {
                cout << "YES" << "\n";
            }
            else
            {
                cout << "NO" << "\n";
            }
        }
        if (g == 0)
        {
            for (int y = 0; y < l; y++)
            {
                c = s[y];
                for (int u = 0; u < 3; u++)
                {
                    c1 = C[u];
                    if (c1 != c)
                    {
                        s[y] = C[u];
                        if (M.find(s) != M.end())
                        {
                            g = 1;
                            cout << "YES" << "\n";
                            u = 4;
                        }
                    }
                }
                s[y] = c;
                if (g == 1)
                {
                    y += l;
                }
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
vector <string> V;
string s, S="";

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1, C[3];
    C[0] = 'a';
    C[1] = 'b';
    C[2] = 'c';
    for (int i = 0; i < 300000; i++)
    {
        s += 'a';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
        V.push_back(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        if (n < 3)
        {
            for (int y = 0; y < n; y++)
            {
                if (s == V[y])
                {
                    g = 1;
                    cout << "NO" << "\n";
                }
            }
        }
        if (g == 0)
        {
            for (int y = 0; y < l; y++)
            {
                c = s[y];
                for (int u = 0; u < 3; u++)
                {
                    c1 = C[u];
                    if (c1 != c)
                    {
                        s[y] = C[u];
                        if (M.find(s) != M.end())
                        {
                            g = 1;
                            cout << "YES" << "\n";
                            u = 4;
                        }
                    }
                }
                s[y] = c;
                if (g == 1)
                {
                    y += l;
                }
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
vector <string> V;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g, k;
    cin >> n >> m;
    char c, c1, C[3];
    C[0] = 'a';
    C[1] = 'b';
    C[2] = 'c';
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
        V.push_back(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        if (n < 2)
        {
            g = 1;
            if (s == V[0])
            {
                cout << "NO" << "\n";
            }
            else if (s.length() == V[0].length())
            {
                k = 1;
                for (int y = 0; y < l; y++)
                {
                    if (s[y] != V[0][y])
                    {
                        k--;
                    }
                    if (k < 0)
                    {
                        y += l;
                    }
                }
                if (k == 0)
                {
                    cout << "YES" << "\n";
                }
                else
                {
                    cout << "NO" << "\n";
                }
            }
            else
            {
                cout << "NO" << "\n";
            }
        }
        if (g == 0)
        {
            for (int y = 0; y < l; y++)
            {
                c = s[y];
                for (int u = 0; u < 3; u++)
                {
                    c1 = C[u];
                    if (c1 != c)
                    {
                        s[y] = C[u];
                        if (M.find(s) != M.end())
                        {
                            g = 1;
                            cout << "YES" << "\n";
                            u = 4;
                        }
                    }
                }
                s[y] = c;
                if (g == 1)
                {
                    y += l;
                }
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
vector <string> V;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g, k;
    cin >> n >> m;
    char c, c1, C[3];
    C[0] = 'a';
    C[1] = 'b';
    C[2] = 'c';
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
        V.push_back(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        if (n < 11)
        {
            for (int j = 0; j < n; j++)
            {
                if (s.length() == V[j].length())
                {
                    k = 1;
                    for (int y = 0; y < l; y++)
                    {
                        if (s[y] != V[j][y])
                        {
                            k--;
                        }
                        if (k < 0)
                        {
                            y += l;
                        }
                    }
                    if (k == 0)
                    {
                        cout << "YES" << "\n";
                        g = 1;
                        j += n;
                    }
                }
            }
            if (g == 0)
            {
                g = 1;
                cout << "NO" << "\n";
            }
        }
        if (g == 0)
        {
            for (int y = 0; y < l; y++)
            {
                c = s[y];
                for (int u = 0; u < 3; u++)
                {
                    c1 = C[u];
                    if (c1 != c)
                    {
                        s[y] = C[u];
                        if (M.find(s) != M.end())
                        {
                            g = 1;
                            cout << "YES" << "\n";
                            u = 4;
                        }
                    }
                }
                s[y] = c;
                if (g == 1)
                {
                    y += l;
                }
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map <string, bool> M;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M[s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M.find(s) != M.end())
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

unordered_map <string, bool> M[600001];
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        l = s.length();
        M[l][s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[l][s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map <string, int> M;
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M[s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

set <string> M;
vector <string> V;
string s, S="";

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1, C[3];
    C[0] = 'a';
    C[1] = 'b';
    C[2] = 'c';
    for (int i = 0; i < 300000; i++)
    {
        s += 'a';
    }
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M.insert(s);
        V.push_back(s);
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        if (n < 2)
        {
            g = 1;
            if (s == V[0])
            {
                cout << "NO" << "\n";
            }
            else
            {
                cout << "YES" << "\n";
            }
        }
        if (g == 0)
        {
            for (int y = 0; y < l; y++)
            {
                c = s[y];
                for (int u = 0; u < 3; u++)
                {
                    c1 = C[u];
                    if (c1 != c)
                    {
                        s[y] = C[u];
                        if (M.find(s) != M.end())
                        {
                            g = 1;
                            cout << "YES" << "\n";
                            u = 4;
                        }
                    }
                }
                s[y] = c;
                if (g == 1)
                {
                    y += l;
                }
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map <string, int> M;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    string s;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M[s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                        y += l;
                    }
                }
            }
            s[y] = c;
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    string s;
    char c, c1;
    map <string, int> M;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        M[s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                        y += l;
                    }
                }
            }
            s[y] = c;
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map <string, bool> M[600001];
string s;

int main()
{
    ios::sync_with_stdio(false);
    int n, m, l, g;
    cin >> n >> m;
    char c, c1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        l = s.length();
        M[l][s] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        cin >> s;
        l = s.length();
        g = 0;
        for (int y = 0; y < l; y++)
        {
            c = s[y];
            for (int u = 0; u < 3; u++)
            {
                c1 = 'a' + u;
                if (c1 != c)
                {
                    s[y] = c1;
                    if (M[l][s] == 1)
                    {
                        g = 1;
                        cout << "YES" << "\n";
                        u = 4;
                    }
                }
            }
            s[y] = c;
            if (g == 1)
            {
                y += l;
            }
        }
        if (g == 0)
        {
            cout << "NO" << "\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define bug(x) cout<<x<<endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int siz = 1e6+5;
set<int>ss;
int A = 11,n,m,a[siz],base[siz];
int get_hash(string s)
{
    int ret = 0;
    for(int i = 0;i<s.size();i++)
    {
        ret+=s[i]*base[i]; ret%=mod;
    }
    return ret;
}
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);

   cin>>n>>m;
   base[0] = 1;
   for(int i = 1;i<siz;i++)  base[i] = (base[i-1]*A)%mod;
   for(int i = 1;i<=n;i++)
   {
       string s; cin>>s;
       ss.insert(get_hash(s));
   }
   while(m--)
   {
       string s; cin>>s;
       int cur = get_hash(s);
       int p = 0;
       for(int i = 0;i<s.size();i++)
       {
           for(char c = 'a';c<='c';c++)
           {
               if(c == s[i]) continue;
               int t = cur+(c-s[i])*base[i];
               t+=mod; t%=mod;
               if(ss.count(t)) p = 1;
           }
       }
       if(p) cout<<"YES\n";
       else cout<<"NO\n";
   }

}