#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 200 + 5;
const int maxl = 1000000 + 5;
int n, m, q;
int g[maxn][maxn];
int a[10], b[10];
bool mrk[maxn][maxn], vis[maxn][maxn];
int cx[maxn][maxn], cy[maxn][maxn], S[maxn][maxn];
char s[maxl];
int suf[maxl];
inline void go(int &x, int &y) {
  int nx = x + a[g[x][y]], ny = y + b[g[x][y]];
  if (1 <= nx && nx <= n && 1 <= ny && ny <= m) x = nx, y = ny;
}
void init() {
  memset(S, -1, sizeof(S));
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      int x = i, y = j;
      go(x, y), mrk[x][y] = true;
    }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j)
      if (!mrk[i][j]) {
        int x = i, y = j;
        do vis[x][y] = true, go(x, y);
        while (!vis[x][y]);
        if (S[x][y] == -1) {
          int u = x, v = y, w = 0;
          do w |= 1 << g[u][v], go(u, v);
          while (u != x || v != y);
          do cx[u][v] = u, cy[u][v] = v, S[u][v] = w, go(u, v);
          while (u != x || v != y);
        }
        int u = i, v = j;
        do
          cx[u][v] = cx[x][y], cy[u][v] = cy[x][y], S[u][v] = S[x][y], go(u, v);
        while (u != x || v != y);
      }
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j)
      if (!vis[i][j]) {
        mrk[i][j] = false;
        int x = i, y = j, z = 0;
        do z |= 1 << g[x][y], go(x, y);
        while (x != i || y != j);
        do cx[x][y] = x, cy[x][y] = y, S[x][y] = z, go(x, y);
        while (x != i || y != j);
      }
}
bool find() {
  int l = strlen(s);
  suf[l] = 0;
  for (int i = l - 1; i >= 0; --i) suf[i] = suf[i + 1] | (1 << (s[i] - '0'));
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j)
      if (!mrk[i][j]) {
        int x = i, y = j, p = 0;
        for (; x != cx[i][j] || y != cy[i][j]; go(x, y))
          if (g[x][y] == s[p] - '0' && !s[++p]) return true;
        if ((suf[p] & S[i][j]) == suf[p]) return true;
      }
  return false;
}
int main() {
  scanf("%d%d%d", &n, &m, &q);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) scanf("%1d", &g[i][j]);
  for (int i = 0; i < (10); ++i) scanf("%d%d", &a[i], &b[i]);
  init();
  while (q--) {
    scanf("%s", s);
    puts(find() ? "YES" : "NO");
  }
  return 0;
}
