#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const int M = N * N;
struct map {
  int x, y, s;
} l[M];
int n, m, q, a[N][N], G[N][N][2], u, v, x, y, len, f[2000], tot, S[M][2], h,
    ans, g[N][N], to[10][2];
bool o[N][N], O[N][N];
char s[1000005];
void dfs(int x, int y) {
  if (o[x][y]) return;
  o[x][y] = O[x][y] = 1;
  tot++;
  S[tot][0] = x;
  S[tot][1] = y;
  u = x + G[x][y][0];
  v = y + G[x][y][1];
  if (u <= 0 || v <= 0 || u > n || v > m) u = x, v = y;
  if (O[u][v]) {
    h++;
    l[h].x = x;
    l[h].y = y;
    for (; S[tot + 1][0] != u || S[tot + 1][1] != v; tot--)
      l[h].s |= 1 << a[S[tot][0]][S[tot][1]];
    O[x][y] = 0;
    return;
  }
  dfs(u, v);
  h++;
  l[h].x = x;
  l[h].y = y;
  tot--;
  O[x][y] = 0;
}
int main() {
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    getchar();
    for (int j = 1; j <= m; j++) a[i][j] = getchar() - '0';
  }
  for (int i = 0; i <= 9; i++) scanf("%d%d", &to[i][0], &to[i][1]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      G[i][j][0] = to[a[i][j]][0], G[i][j][1] = to[a[i][j]][1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!o[i][j]) dfs(i, j);
  for (int i = 1; i <= q; i++) {
    scanf("\n%s", s);
    len = strlen(s);
    u = ans = 0;
    memset(f, 10, sizeof(f));
    memset(g, 10, sizeof(g));
    for (int j = len - 1; j >= 0; j--) {
      u |= 1 << (s[j] - '0');
      f[u] = j;
    }
    for (int S = 1; S < (1 << 10); S++)
      for (int j = 0; j <= 9; j++)
        if (S & (1 << j)) f[S] = min(f[S], f[S - (1 << j)]);
    for (int j = 1; j <= n * m; j++) {
      x = l[j].x;
      y = l[j].y;
      if (l[j].s)
        g[x][y] = f[l[j].s];
      else {
        u = x + G[x][y][0];
        v = y + G[x][y][1];
        g[x][y] = g[u][v] - (g[u][v] < len && s[g[u][v] - 1] - '0' == a[x][y]);
        if (s[len - 1] - '0' == a[x][y] && g[x][y] > len) g[x][y] = len - 1;
      }
      if (!g[x][y]) {
        ans = 1;
        break;
      }
    }
    if (ans)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
