#include <bits/stdc++.h>   using namespace std;   const int N = 200 + 5;   const int LEN = 1e6 + 10;   int n, m, q;   int a[N];   int b[N];   int f[N][N];   char ch[LEN];   int g[LEN], l;   int xt[N * N], yt[N * N];   int dp[N][N];   int cnt, cir[N * N][10];   int lc[N * N];   int c0[N][N];   int bel[N][N];   int nx[N][N], ny[N][N];   int rd[N][N];   int v[N][N], cc;   int pre[N][N];   bool check(int x, int y) {     if (x <= 0 || y <= 0 || x >= n + 1 || y >= m + 1)       return false;     else       return true;   }   void dfs_1(int x, int y) {     v[x][y] = cc;     int x0 = nx[x][y], y0 = ny[x][y];     if (v[x0][y0] > 0) {       if (v[x0][y0] == cc) c0[x0][y0] = ++cnt;       return;     }     dfs_1(x0, y0);   }   void dfs_2(int x, int y, int k) {     v[x][y] = k;     bel[x][y] = k;     cir[k][f[x][y]] = true;     int x0 = nx[x][y], y0 = ny[x][y];     if (v[x0][y0] > 0) return;     dfs_2(x0, y0, k);   }   void init() {     cin >> n >> m >> q;     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; i++) {       scanf( %s , ch);       for (int j = 1; j <= m; j++) f[i][j] = ch[j - 1] -  0 ;     }     for (int i = 0; i < 10; i++) scanf( %d %d , &a[i], &b[i]);     cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         nx[i][j] = i + a[f[i][j]];         ny[i][j] = j + b[f[i][j]];         if (!check(nx[i][j], ny[i][j])) {           nx[i][j] = i;           ny[i][j] = j;           bel[i][j] = ++cnt;           v[i][j] = cnt;           cir[cnt][f[i][j]] = true;         }         rd[nx[i][j]][ny[i][j]]++;       }     cc = cnt;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (v[i][j] == 0) {           cc++;           dfs_1(i, j);         }     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (c0[i][j] > 0) {           dfs_2(i, j, c0[i][j]);         }   }   bool bfs() {     int L, R, x1, y1, x2, y2;     L = 1, R = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (rd[i][j] == 0) {           R++;           xt[R] = i, yt[R] = j;           pre[i][j] = 0;         } else           pre[i][j] = rd[i][j];     while (L <= R) {       x1 = xt[L], y1 = yt[L];       x2 = nx[x1][y1], y2 = ny[x1][y1];       if (dp[x1][y1] >= l) return true;       if (g[dp[x1][y1] + 1] == f[x1][y1]) dp[x1][y1]++;       dp[x2][y2] = max(dp[x1][y1], dp[x2][y2]);       pre[x2][y2]--;       if (pre[x2][y2] == 0) {         R++;         xt[R] = x2, yt[R] = y2;       }       if (bel[x2][y2] != 0) {         if (lc[bel[x2][y2]] <= dp[x2][y2]) return true;       }       L++;     }     return false;   }   void work() {     bool sign;     for (int i = 1; i <= q; i++) {       scanf( %s , ch);       l = strlen(ch);       memset(dp, 0, sizeof(dp));       for (int j = 1; j <= l; j++) g[j] = ch[j - 1] -  0 ;       sign = false;       for (int j = 1; j <= cnt; j++) {         lc[j] = l;         while (cir[j][g[lc[j]]] && lc[j] != 0) lc[j]--;         if (lc[j] == 0) {           sign = true;           break;         }       }       if (sign) {         cout <<  YES  << endl;         continue;       }       if (bfs())         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }   int main() {     init();     work();     return 0;   }