#include <bits/stdc++.h>
using namespace std;
const int N = 210;
const int M = 1e6 + 10;
const int inf = 1e9;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m, q, val[N * N], nxt[N * N], a[N], b[N];
int id(int x, int y) { return (x - 1) * m + y; }
int vis[N * N], bel[N * N], cnt = 0;
vector<int> ring[N * N], E[N * N];
bool have[N * N][10];
char s[M];
int t[M], len, fst[10];
void dfs(int u) {
  if (vis[u] == 2) return;
  if (vis[u] == 1) {
    int v = u;
    ++cnt;
    do have[cnt][val[v]] = 1, bel[v] = cnt, ring[cnt].push_back(v), v = nxt[v];
    while (v != u);
    vis[u] = 2;
    return;
  }
  vis[u] = 1;
  dfs(nxt[u]);
  vis[u] = 2;
}
bool dfs(int u, int p) {
  if (p <= len && val[u] == t[p]) p++;
  if (p == len + 1) return 1;
  for (int v : E[u])
    if (dfs(v, p)) return 1;
  return 0;
}
bool check() {
  for (int i = 1; i <= cnt; i++) {
    int p = inf;
    for (int j = 0; j <= 9; j++)
      if (!have[i][j]) p = min(p, fst[j]);
    if (p == inf) return 1;
    for (int u : ring[i])
      if (dfs(u, p)) return 1;
  }
  return 0;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char ch = getchar();
      while (!isdigit(ch)) ch = getchar();
      val[id(i, j)] = ch - '0';
    }
  for (int i = 0; i <= 9; i++) a[i] = gi(), b[i] = gi();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x = i + a[val[id(i, j)]], y = j + b[val[id(i, j)]];
      if (x < 1 || x > n || y < 1 || y > m) x = i, y = j;
      nxt[id(i, j)] = id(x, y);
    }
  n *= m;
  for (int i = 1; i <= n; i++) dfs(i);
  for (int i = 1; i <= n; i++)
    if (!bel[i]) E[nxt[i]].push_back(i);
  while (q--) {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    for (int i = 0; i <= 9; i++) fst[i] = inf;
    for (int i = 1; i <= len; i++)
      t[i] = s[len - i + 1] - '0', fst[t[i]] = min(fst[t[i]], i);
    puts(check() ? "YES" : "NO");
  }
  return 0;
}
