// Arup Guha
// 10/24/2016
// Solution to 2016 NCPC Problem B: Bless You Autocorrect

import java.util.*;
import java.io.*;

public class b {

	public static int n;
	public static String[] dictionary;
	public static tri words;

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		n = Integer.parseInt(tok.nextToken());
		dictionary = new String[n];
		int numCheck = Integer.parseInt(tok.nextToken());

		// Set up dictionary.
		words = new tri(0, -1, 0);
		for (int i=0; i<n; i++) {
			dictionary[i] = stdin.readLine().trim();
			words.insert(dictionary[i].toCharArray(), i);
		}

		// Process each query.
		for (int i=0; i<numCheck; i++) {
			String type = stdin.readLine().trim();
			System.out.println(solve(type.toCharArray()));
		}

	}

	public static int solve(char[] list) {

		int curRes = 0, alt = 10000000;
		int prevIndex = -1;

		tri ptr = words;

		// Go through each letter.
		for (int i=0; i<list.length; i++) {

			// Possibility of just typing this letter.
			curRes++;

			// Have to type the rest.
			if (ptr.next[list[i]-'a'] == null) return curRes + list.length - (i+1);

			// New jump.
			if (prevIndex != ptr.next[list[i]-'a'].pIndex)
				alt = curRes + ptr.next[list[i]-'a'].pLen - i;

			// Same as old jump but gaining a letter.
			else
				alt--;

			// See if the jump is better.
			curRes = Math.min(curRes, alt);

			// Update variables for next iteration.
			prevIndex = ptr.next[list[i]-'a'].pIndex;
			ptr = ptr.next[list[i]-'a'];
		}

		return curRes;
	}
}

class tri {

	public int level;
	public int pIndex;
	public int pLen;
	public tri[] next;

	public tri(int myL, int index, int len) {
		level = myL;
		pIndex = index;
		pLen = len;
		next = new tri[26];
		Arrays.fill(next, null);
	}

	public void insert(char[] word, int index) {

		// Base case.
		if (level == word.length) return;

		// Create the node if it's not there.
		if (next[word[level]-'a'] == null)
			next[word[level]-'a'] = new tri(level+1, index, word.length);

		// Recursively insert it.
		next[word[level]-'a'].insert(word, index);
	}
}