import java.util.List;
import java.util.NavigableSet;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.SortedSet;
import java.util.Set;
import java.util.Comparator;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.TreeSet;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class caption_egor {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("caption.in");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("caption.out");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		Caption solver = new Caption();
		solver.solve(1, in, out);
		out.close();
	}
}

class Caption {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int rowCount = in.readInt();
		int columnCount = in.readInt();
		final int width = in.readInt();
		int minSpacing = in.readInt();
		int maxSpacing = in.readInt();
		int[] letterIndex = new int[256];
		Arrays.fill(letterIndex, -1);
		List<char[]> firstRow = new ArrayList<char[]>();
		char[] current;
		int index = 0;
		while (true) {
			current = in.readString().toCharArray();
			if (current.length == 1) {
				firstRow.add(in.readString().toCharArray());
				letterIndex[current[0]] = index++;
			} else
				break;
		}
		letterIndex[' '] = index++;
		char[][][] letters = new char[index][rowCount][];
		for (int i = 0; i < index - 1; i++)
			letters[i][0] = firstRow.get(i);
		letters[0][1] = current;
		for (int i = 1; i < rowCount; i++) {
			for (int j = (i == 1 ? 1 : 0); j < index - 1; j++)
				letters[j][i] = in.readString().toCharArray();
		}
		for (int i = 0; i < rowCount; i++) {
			letters[index - 1][i] = new char[width];
			Arrays.fill(letters[index - 1][i], '.');
		}
		char[] was = in.readLine().toCharArray();
		int[] spacing = new int[was.length];
		for (int i = 0; i < spacing.length; i++)
			spacing[i] = in.readInt();
		char[] need = in.readLine().toCharArray();
		char[][] image = new char[rowCount][columnCount];
		for (int i = 0; i < rowCount; i++)
			Arrays.fill(image[i], '.');
		int position = 0;
		for (int i = 0; i < was.length; i++) {
			position += spacing[i];
			for (int j = 0; j < rowCount; j++) {
				System.arraycopy(letters[letterIndex[was[i]]][j], 0, image[j], position, width);
			}
			position += width;
		}
		final int[] freeCost = new int[columnCount + 1];
		for (int i = 0; i < columnCount; i++) {
			freeCost[i + 1] = freeCost[i];
			for (int j = 0; j < rowCount; j++) {
				if (image[j][i] == '*')
					freeCost[i + 1]++;
			}
		}
		int[][] letterCost = new int[256][columnCount - width + 1];
		for (int i = 0; i < 256; i++) {
			if (letterIndex[i] == -1)
				continue;
			for (int j = 0; j <= columnCount - width; j++) {
				for (int k = 0; k < rowCount; k++) {
					for (int l = 0; l < width; l++) {
						if (letters[letterIndex[i]][k][l] != image[k][j + l])
							letterCost[i][j]++;
					}
				}
			}
		}
		final int[][] result = new int[need.length][columnCount - width + 1];
		int[][] last = new int[need.length][columnCount - width + 1];
		for (int i = 0; i <= columnCount - width; i++)
			result[0][i] = freeCost[i] + letterCost[need[0]][i];
		for (int i = 1; i < need.length; i++) {
			final int finalI = i;
			NavigableSet<Integer> queue = new TreeSet<Integer>(new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					int value = result[finalI - 1][o1] - freeCost[o1 + width] - result[finalI - 1][o2] + freeCost[o2 + width];
					if (value != 0)
						return value;
					return o1 - o2;
				}
			});
			for (int j = 0; j <= columnCount - width; j++) {
				index = j - minSpacing - width;
				if (index >= 0 && result[i - 1][index] != Integer.MAX_VALUE)
					queue.add(index);
				if (queue.isEmpty())
					result[i][j] = Integer.MAX_VALUE;
				else {
					int head = queue.first();
					result[i][j] = result[i - 1][head] - freeCost[head + width] + freeCost[j] + letterCost[need[i]][j];
					last[i][j] = head;
				}
				index = j - maxSpacing - width;
				if (index >= 0 && result[i - 1][index] != Integer.MAX_VALUE)
					queue.remove(index);
			}
		}
		int min = Integer.MAX_VALUE;
		int minIndex = -1;
		for (int i = 0; i <= columnCount - width; i++) {
			if (result[need.length - 1][i] == Integer.MAX_VALUE)
				continue;
			result[need.length - 1][i] += freeCost[columnCount] - freeCost[i + width];
			if (min > result[need.length - 1][i]) {
				min = result[need.length - 1][i];
				minIndex = i;
			}
		}
		int[] newPosition = new int[need.length];
		newPosition[need.length - 1] = minIndex;
		for (int i = need.length - 1; i > 0; i--) {
			minIndex = last[i][minIndex];
			newPosition[i - 1] = minIndex;
		}
		for (int i = need.length - 1; i > 0; i--)
			newPosition[i] -= newPosition[i - 1] + width;
		out.print(newPosition[0]);
		for (int i = 1; i < need.length; i++)
			out.print("", newPosition[i]);
		out.printLine();
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private String readLine0() {
		StringBuffer buf = new StringBuffer();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(outputStream);
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

