// Arup Guha
// 3/13/2018
// Solution to 2018 UCF HS Contest Problem: Number Search

import java.util.*;

public class number {

	// Directions of movement.
	final public static int[] DX = {-1,-1,-1,0,0,1,1,1};
	final public static int[] DY = {-1,0,1,-1,1,-1,0,1};

	// Grid info.
	public static int r;
	public static int c;
	public static char[][] grid;

	// Store all possible values here.
	public static HashSet<Long> vals;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=nC; loop++) {

			// Get the grid.
			r = stdin.nextInt();
			c = stdin.nextInt();
			grid = new char[r][];
			for (int i=0; i<r; i++)
				grid[i] = stdin.next().toCharArray();

			// Get all possible values.
			fillHashSet();

			// Header.
			System.out.println("Number Search #"+loop+":");
			int q = stdin.nextInt();

			// Go through each query.
			for (int i=0; i<q; i++) {

				// Just see if the value is in our set.
				long val = stdin.nextLong();
				if (vals.contains(val))
					System.out.println("Yes");
				else
					System.out.println("No");
			}
			System.out.println();
		}
	}

	public static void fillHashSet() {

		// Need to make this.
		vals = new HashSet<Long>();

		// Try each starting square.
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {

				// And each direction.
				for (int dir=0; dir<DX.length; dir++) {

					// And each length.
					for (int len=1; len<=15; len++) {

						// Where we would end.
						int endx = i + DX[dir]*(len-1);
						int endy = j + DY[dir]*(len-1);

						// Get out if we go off the grid.
						if (!inbounds(endx, endy)) break;

						// Here is our string.
						String tmp = get(i, j, dir, len);

						// Convert it to a number (null if not valid) and add it.
						Long val = getVal(tmp);
						if (val != null) vals.add(val);
					}
				}
			}
		}
	}

	// Pre-condition: A string starting at (x,y) in direction dir of length len
	//                doesn't cause an array out of bounds.
	// Post-condition: The aforementioned String is returned.
	public static String get(int x, int y, int dir, int len) {
		char[] res = new char[len];
		for (int i=0; i<len; i++)
			res[i] = grid[x+i*DX[dir]][y+i*DY[dir]];
		return new String(res);
	}

	public static Long getVal(String s) {

		// Count # of ops and keep track of last op seen.
		int numOps = 0, opPos = -1;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) < '1' || s.charAt(i) > '9') {
				numOps++;
				opPos = i;
			}
		}

		// Not allowed in the problem statement.
		if (numOps > 1) return null;

		// Trick case (sort of) - expression starts or ends in an operator.
		if (opPos == 0 || opPos == s.length()-1) return null;

		// All digits, just convert to a long.
		if (numOps == 0) return Long.parseLong(s);

		// Get values of left and right of operator.
		long left = Long.parseLong(s.substring(0, opPos));
		long right = Long.parseLong(s.substring(opPos+1));

		// Return accordingly.
		char op = s.charAt(opPos);
		if (op == '+') return left+right;
		else if (op == '-') return left-right;
		else if (op == '*') return left*right;

		// Division is annoying
		else {
			if (left%right != 0) return null;
			return left/right;
		}
	}

	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < r && y >= 0 && y < c;
	}
}