#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000 + 100;
const int maxm = 1000000 + 100;
const int maxn = 310;
int n, m, qq;
int dx[20], dy[20];
char cmd[maxm];
char str[maxn][maxn];
int sum[maxm][10];
int vis[maxn][maxn], used[maxn][maxn];
int c[maxn], d[maxn];
int A[maxn][maxn][10], B[maxn][maxn][10];
void dfs() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int x = i, y = j;
      vector<int> G1, G2;
      if (vis[x][y]) continue;
      vis[x][y] = i * m + j;
      d[str[x][y] - '0']++;
      for (int t = 0; t < 200000; t++) {
        G1.push_back(x);
        G2.push_back(y);
        int nx = x + dx[str[x][y] - '0'], ny = y + dy[str[x][y] - '0'];
        if (nx >= 0 && ny >= 0 && nx < n && ny < m) {
          x = nx;
          y = ny;
        }
        if (vis[x][y] == i * m + j + n * m) break;
        if (vis[x][y] != i * m + j) {
          vis[x][y] = i * m + j;
          d[str[x][y] - '0']++;
        } else {
          vis[x][y] = i * m + j + n * m;
          c[str[x][y] - '0']++;
          d[str[x][y] - '0']--;
        }
      }
    }
}
void solve() {
  memset(vis, -1, sizeof(vis));
  memset(used, 0, sizeof(used));
  scanf("%s", cmd);
  int len = strlen(cmd);
  for (int k = 0; k < 10; k++) sum[len][k] = 0;
  for (int i = len - 1; i >= 0; i--) {
    for (int k = 0; k < 10; k++) sum[i][k] = sum[i + 1][k];
    sum[i][cmd[i] - '0']++;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int x = i, y = j;
      if (used[x][y]) continue;
      memset(c, 0, sizeof c);
      int pos = 0;
      for (int t = 0; t < 200000; t++) {
        used[x][y] = 1;
        if (str[x][y] == cmd[pos]) pos++;
        int nx = x + dx[str[x][y] - '0'], ny = y + dy[str[x][y] - '0'];
        if (nx >= 0 && ny >= 0 && nx < n && ny < m) x = nx, y = ny;
        if (vis[x][y] == i * m + j + n * m) break;
        if (vis[x][y] != i * m + j)
          vis[x][y] = i * m + j;
        else {
          vis[x][y] = i * m + j + n * m;
          c[str[x][y] - '0']++;
        }
      }
      int check = 1;
      for (int k = 0; k <= 9; k++)
        if (sum[pos][k] && !c[k]) check = 0;
      if (check) {
        printf("YES\n");
        return;
      }
    }
  printf("NO\n");
}
int main() {
  scanf("%d%d%d", &n, &m, &qq);
  for (int i = 0; i < n; i++) scanf("%s", str[i]);
  for (int i = 0; i < 10; i++) scanf("%d%d", &dx[i], &dy[i]);
  while (qq--) solve();
  return 0;
}
