#include <bits/stdc++.h>
#define NAME "hidden"
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,a ,b) for(int i = (a), _b = (b); i >= _b; --i)
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int maxN = 100;
int n, m, k;
char a[maxN][maxN];
string s;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
priority_queue<iii> q;
int d[maxN][maxN][maxN];
void io()
{
	freopen(NAME".inp", "r", stdin);
	freopen(NAME".out", "w", stdout);
}
bool check(string s)
{
	int _l = s.size() - 1;
	while (q.size()) q.pop();
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			FOR(k, 0, _l) d[i][j][k] = 0;
		}
	}
	FOR(i, 1, n)
	{
		FOR(j, 1, m)
		{
			if (a[i][j] == s[0]) {
				q.push(iii(0, ii(i, j)));
				d[i][j][0] = 1;
			}
		}
	}
	while (q.size())
	{
		int u = q.top().se.fi;
		int v = q.top().se.se;
		int l = q.top().fi;
		d[u][v][l] = 1;
		q.pop();
		if (l >= _l) return true;
		if (u + 1 <= n && a[u + 1][v] == s[l + 1] && !d[u + 1][v][l + 1]) q.push(iii(l + 1, ii(u + 1, v)));
		if (u > 1 && a[u - 1][v] == s[l + 1] && !d[u - 1][v][l + 1]) q.push(iii(l + 1, ii(u - 1, v)));
		if (v + 1 <= m && a[u][v + 1] == s[l + 1] && !d[u][v + 1][l + 1]) q.push(iii(l + 1, ii(u, v + 1)));
		if (v > 1 && a[u][v - 1] == s[l + 1] && !d[u][v - 1][l + 1]) q.push(iii(l + 1, ii(u, v - 1)));
	}
	return false;
}
int main()
{
	io();
	cin >> n >> m;
	FOR(i, 1, n) FOR(j, 1, m) {
		cin >> a[i][j];
	}
	cin >> k;
	FOR(i, 1, k)
	{
		cin >> s;
		if (check(s)) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}
/*
5 6
nmalah
tthocw
elpnsi
itighn
vdofkm
*/